Solved

Crash course in java threads

Posted on 2007-12-02
9
164 Views
Last Modified: 2010-03-30
Hi,

Can someone provide me with a snippet or good link to show how to create a 'worker' thread in java. I don't know if that terminology is used, Im takin it from my C++ stuff. I would like to do the following:

1) Start the main application
2) Create a new thread - have it open a local file.
3) The new thread notifies the main thread that it's terminating
4) The main thread prints something like "loading....." while it's waiting for the new thread to finish.

Thanks
0
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 20392570
0
 
LVL 92

Expert Comment

by:objects
ID: 20392574
Sounds like the SwingWorker is what you need.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20392575
Have a look at SwingWorker in 1.6
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 86

Expert Comment

by:CEHJ
ID: 20392582
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20392586
Yeah but I read swing was a huge download for the end user? I want my applet to be lightweight, isn't there any thread stuff built into the java core? I really have no idea what I'm talking about since I'm new to java, just thought there'd be something built in. Please feel free to correct me!
0
 
LVL 92

Expert Comment

by:objects
ID: 20392634
swing is part of the standard install (has been since java2)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20392635
There's nothing to download. Swing will already be in the JRE of the user
0
 
LVL 92

Expert Comment

by:objects
ID: 20392637
And SwingWorker is standard in 1.6. And is only a single class if you want to support earlier versions of java.

see the links I posted earlier for how to use it.
0
 
LVL 92

Expert Comment

by:objects
ID: 20392669
heres an example that shows it being used to do some long calculations and update the gui for the progress

http://www.java2s.com/Code/Java/Swing-JFC/SwingworkerExample.htm

And some background
http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question