Solved

Crash course in java threads

Posted on 2007-12-02
9
163 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

734 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