Crash course in java threads

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
DJ_AM_JuiceboxAsked:
Who is Participating?
 
objectsCommented:
Sounds like the SwingWorker is what you need.
0
 
CEHJCommented:
Have a look at SwingWorker in 1.6
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
DJ_AM_JuiceboxAuthor Commented:
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
 
objectsCommented:
swing is part of the standard install (has been since java2)
0
 
CEHJCommented:
There's nothing to download. Swing will already be in the JRE of the user
0
 
objectsCommented:
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
 
objectsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.