-
MultiThreading Problem
I am having a basic problem
I have a class GUi which is showing the GUi of the project
and a class where i process the data
Now when i click on start button the class which process the data is called and when the data being processed at that time GUi frame hangs and buttons get inactive.
Now i know it will be solved by threading so can u help me how to do it .
Eg:
GUI.java
Code:
class GUI
{
.....
void actionListener(...)
{
new A();
}
}
A.java
now when A is called the frame in GUI gets inactive but the data processing is performed normally.
Thanks in advance
-
You can create threads in two ways, using Thread class as well as Runnable interface.
Code:
class A extends Thread {
public void run() {
// Implementation
}
}
Then start the thread.
Code:
class B {
.......
A objA = new A();
objA.start();
}
That's very basis of Thread. Read more about in Suns' official website.
Lesson: Concurrency (The Java™ Tutorials > Essential Classes)
-
Your problem is that you're calling a long-running process on the EDT, the Event Dispatch Thread, the main thread that Swing uses to do painting and user interaction, and when this happens, Swing simply freezes in its tracts. The solution is to do your background process in a a background thread like a SwingWorker. For details, please look here: Concurrency in Swing
-
And also search the forum, Java Tip section as well. You can find lots of similar discussion related to.
-
thank you i have solved it by running the data processing in new thread
thank u
-
If you have solved the problem, please mark the thread solved. :)
-
well as per my knowledge the thread is marked solved isnt it?
-
Oops, I just seen that. Sorry about lol, normally I'm accessing threads from the list, and hard to see it at once. )
-
no problem , well have to read my new "MultiThreading part 2" thread i need help so desperately please if you can help me