Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with implementation - should I use threads???

 
Pedro Cristo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have recently (2 months ago) started to learn java altought I have already experience of another languages. One of the things that I don't have experience in, is threads and I'm trying to develop an application and I think the problem is related with threads. Let me explain.

I'm developing an application to work on lottery statistics with the possibility to filter the combinations result using filters.
So, the user picks numbers from a range and my software will get each combination possible, check it against the filter(s) condition(s) and add the combination to a list or a file.

At the moment, I have all this implemented (with just one filter...) but the problem is that the GUI hangs because I'm not using threads. The process is very quick at the moment, even with many more filters. The problem is that I don't want the GUI to hang up.

So, my question is: how can I implement this with threads (or any other solution that doesn't hang up the GUI)??? Where do I implement the thread or threads? In the MainWindow class? In the Filters class?? On both?

Those are my doubts about Threads in java.

Here is my code:





 
Tony Docherty
Bartender
Posts: 2958
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but the problem is that the GUI hangs because I'm not using threads

All applications use threads whether you explicitly create them or not. The GUI hangs because you are doing all the computation on the Event Dispatch Thread which is the only thread that interacts with Swing components.
I don't have time to go through all your code to see exactly what you are doing but if you have a long running task that updates the GUI then the solution is generally to use a javax.swing.SwingWorker.
 
Pedro Cristo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
but the problem is that the GUI hangs because I'm not using threads

All applications use threads whether you explicitly create them or not. The GUI hangs because you are doing all the computation on the Event Dispatch Thread which is the only thread that interacts with Swing components.
I don't have time to go through all your code to see exactly what you are doing but if you have a long running task that updates the GUI then the solution is generally to use a javax.swing.SwingWorker.


Thanks Tony, i will have a look at that.
When I said that I wasn't using threads I meant that I didn't created a new one to run my code, so you're right.
Anyway, I was trying to implement it and I think I've reached a good solution. I will post my code here when I have time.

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic