I want to start a thread many times, without creating a new Thread evrytime when I need to call my function in a own thread. That´s the reason why I called .run instead of .start because .start can only be called once. So how can I solve my problem?
I have a UI-Programm and want that after pressing any button...
...the first thread disable all buttons
...the second thread enable the buttons, which should be pressed next.
So I have a method in the first thread which disable all buttons and I run it.
Then I run the second thread which enables the buttons. The second thread sleeps for 5 sec and then enables the buttons.
Thread updateUIthread, disableUIthread;
Runnable disableUIrun = new Runnable() {
@Override
public void run() {
disableUserInput();
}
};
Runnable updateUIrun = new Runnable() {
@Override
public void run() {
updateUIinteraction();
}
};
public void updateUIinteraction() {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(VorgangController.class.getName()).log(Level.SEVERE, null, ex);
}
// enable buttons
}
// and when I need it:
disableUIthread.run();
updateUIthread.run();
But when I press a button, the effect is that both threads are sleeping. Nothing happens for 5 sec. then all buttons are disabled and enabled quickly.