Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

is multithreading needed?

 
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)
 
Marshal
Posts: 68917
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing API
 
Sheriff
Posts: 21921
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 21921
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic