Solved

Crash course in java threads

Posted on 2007-12-02
9
162 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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 87
Running JavaFX on JDeveloper 12C 1 78
Java Eclipse Loop 3 31
netbeans can not run self signed app 8 14
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

726 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