Hi,
I am creating a new thread for each of the connections to the server:
public class Node_C
{
....
while (listening) {
Socket client_socket = server_socket.a ccept();
Node_CThread node = new Node_CThread(cl ient_socket);
node.start();
}
}
class Node_CThread extends Thread
{
private Socket socket = null;
public Node_CThrad(Soc ket socket) {
super("Node_CTh read");
this.socket = socket;
}
public void run() {
...
System.out.prin tln("IP address = "...);
System.out.prin tln(" IPcount = "...);
System.out.prin tln(" delay = "...);
}
}
Here is what I need to do:
- I would like to print all the System.out.prin tln() statements that are
related to each other (as shown above) one right after the other for
the same thread. That is, I want the System.out.prin tln() statements
to be printed together for the same thread they belong to.
But, since I am using threads, each line of of each thread is executed
at random intervals. Thus I don't know which line of output belongs
to which thread. Btw, I have already labeled each line of output with
the corresponding thread label, but the output is so messy.
- How could I do that?
I have tried to use synchronized(th is), as well as
synchronized(Sy stem.out) without any luck. That is, the following code
did not work:
public void run() {
...
synchronized(Sy stem.out) {
System.out.prin tln("IP address = "...);
System.out.prin tln(" IPcount = "...);
System.out.prin tln(" delay = "...);
}
}
Any help would be greated appreciated.
Thanks in advance...
-John
I am creating a new thread for each of the connections to the server:
public class Node_C
{
....
while (listening) {
Socket client_socket = server_socket.a ccept();
Node_CThread node = new Node_CThread(cl ient_socket);
node.start();
}
}
class Node_CThread extends Thread
{
private Socket socket = null;
public Node_CThrad(Soc ket socket) {
super("Node_CTh read");
this.socket = socket;
}
public void run() {
...
System.out.prin tln("IP address = "...);
System.out.prin tln(" IPcount = "...);
System.out.prin tln(" delay = "...);
}
}
Here is what I need to do:
- I would like to print all the System.out.prin tln() statements that are
related to each other (as shown above) one right after the other for
the same thread. That is, I want the System.out.prin tln() statements
to be printed together for the same thread they belong to.
But, since I am using threads, each line of of each thread is executed
at random intervals. Thus I don't know which line of output belongs
to which thread. Btw, I have already labeled each line of output with
the corresponding thread label, but the output is so messy.
- How could I do that?
I have tried to use synchronized(th is), as well as
synchronized(Sy stem.out) without any luck. That is, the following code
did not work:
public void run() {
...
synchronized(Sy stem.out) {
System.out.prin tln("IP address = "...);
System.out.prin tln(" IPcount = "...);
System.out.prin tln(" delay = "...);
}
}
Any help would be greated appreciated.
Thanks in advance...
-John
Comment