• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with implementation - should I use threads???

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:





 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
It's feeding time! Give me the food you were going to give to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic