• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with thread  RSS feed

 
Milan Djukic
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I want to run some kind of loading (refreshing text) while programs works in background.
I'm tried with thread but it not works propertly.

This is my algorithm:

1. enter data
2. start loading thread
3a. if data OK stop loading thread and show result
3b. else stop loading thread and return to 1

Thread in run method have infinity loop "while(true)". I stops thread with thread.inrerupt();
Problem is when i enter wrong data second time. When enter data second time thread first stops and then starts! (but first is called start).

I know that threads can do this but how can i solve this?
Thanks!
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think we can help you without some (relevant) code.
 
Milan Djukic
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for late answer.

Here is thread:


Button listener (ActionListener)
 
Milan Djukic
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved this but this is stupid way.
I just sleep client for 100 miliseconds like that:



Whay now works?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're trying to re-invent the wheel. Look at the classes in the java.util.correct package.
With a Future you can complete background tasks in a much cleaner way.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:Look at the classes in the java.util.correct package.


You mean java.util.concurrent, right?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eh... That's correct
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!