The point of threads are to allow a program to mulittask (at least in some cases), but I am needing a thread to multitask.
This is a part of my client and server chat server I have been making for scratch, just to know how to operate a server.
One server side thread gets stuck on this line of code.
command = in.readLine();
waiting for the BufferedReader, aka in, to get a comand from the client.
Of course, once it gets the command, I have a normal thread sleep.
What I am wondering is while I am waiting for something to be present to be read, is there a way to turn the waiting on and off?
I need the thread to multitask.
Started by Lawtonfogle, May 02 2007 02:34 PM
1 reply to this topic
#1
Posted 02 May 2007 - 02:34 PM
|
|
|
#2
Posted 31 May 2007 - 07:14 AM
Lawtonfogle said:
What I am wondering is while I am waiting for something to be present to be read, is there a way to turn the waiting on and off?
Do you mean the waiting after the line is read or do you mean the waiting for that line itself?
In case the sleep/wait after that - just put a boolean variable and if:
... if( shouldSleepAfterRead) Thread.sleep(...); ...set shouldSleepAfterRead from some other thread ( the current is blocked in the reading ).
In case you need to stop the readLine() command - read about interrupt().
You can interrupt a thread:
Thread (Java 2 Platform SE 5.0)
Thread (Java 2 Platform SE 5.0)
Thread (Java 2 Platform SE 5.0)
Hope this helps ...:)


Sign In
Create Account

Back to top









