• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is multithreading needed?

 
bryan lim
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing API
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out javax.swing.SwingWorker. That's the easiest way to handle threading in Swing.
 
bryan lim
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic