aspose file tools*
The moose likes Threads and Synchronization and the fly likes is multithreading needed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "is multithreading needed? " Watch "is multithreading needed? " New topic
Author

is multithreading needed?

bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
hi all

i have a swing application with timer and a jtextarea and a few buttons and fields built in. The jtextarea acts as a console and i will be printing everything out in there.

i realised that when the timer is running and executing instruction, my applciation will freeze and button cannot be press. what is frustrating is that the jtextarea is not updated and only do so after the timer stop.

I thought that timer is running on another thread?

any advise on this ?
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
well. i guess multithreading should be the solution..... anybody got nice multithreading resource to share? those in sun microsystem is pretty old article ( back in 2001)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
Swing API
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

Check out javax.swing.SwingWorker. That's the easiest way to handle threading in Swing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
thank you for the tips.. i am reading the tutorial now......

by the way, if i want to create more than two threads do i create more of the SwingWorker object?

how do i keep track of all these thread and cancel them when i want?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19794
    
  20

You'll need one SwingWorker for each thread you want to run concurrently.

This is going away from Swing and more towards threads in general, so I'm moving this to the threads forum.
bryan lim
Ranch Hand

Joined: Dec 26, 2008
Posts: 140
so if i have different swingworkers ........ how i keep track of them?

which method can allow me to differentiate them? so as to cancel it..... ?

thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is multithreading needed?