I'm creating a java program that in every second there is a data stored into my table. I made use of THread.sleep(1000) to pause the for loop in every second.. But when my program runs, it freezed for 10 seconds because of the condition of my for loop where the counter has not yet reached 10. So my last choice was to use a Thread that will run on different process so as not to freeze the UI cause i've been doing this with .net.... But the big problem is I dont know how will the created thread will have access to the TABLE object which is at the Mainclass.
it2051229
-3
Junior Poster in Training
Recommended Answers
Jump to PostFrom whatever you have posted I assume you need something here where one thread continues the for loop while the other sleeps for 1 sec and then wakes up, is it ? If it is then I suggest you to take a look at the SwingWorker Class. But if it …
Jump to PostYou should never call sleep() in the UI thread (in other words, directly in response to a button click or some other UI handler).
To make the variable visible from another thread, you need to declare it somewhere where it is visible! Possibilities include having a subclass of Thread …
All 6 Replies
verruckt24
438
Posting Shark
neilcoffey
79
Junior Poster in Training
BestJewSinceJC
700
Posting Maven
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
neilcoffey
79
Junior Poster in Training
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.