In my main thread I create two additional threads that I want to use a value from. Basically what I want to do is this:
Threads thread1 = new Threads();
Threads thread2 = new Threads();
Thread.currentThread.wait();
If (thread1 = complete){
var = thread1.getter
//delete thread2
}
If (thread2 == complete){
var = thread2.getter
//delete thread1
}
With thread1 and thread2 having a notify() at the end that wakes up the main thread and the thread that doesn't finish is deleted. But I realise that I don't properly understand wait() and multithreading so the way this is setup may not be correct. I know that Thread.currentThread.wait() is definitely not correct.
I think I may have to synchronize the methods but I have not been able to find any examples that show how to do this in this situation.
Edit: To give more info Thread1 takes input from a scanner and Thread2 takes input from a keylistener and I want to use the first input from 1 of them