You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Seemantini Godbole <SE...@getthere.com> on 2001/08/15 23:26:50 UTC

bug in SocketAppender?

I was looking at some code in SocketAppender, particularly the following
piece:
I understand that the SocketAppender fires another thread, Connector,
whenever it can not reach the remote server. The connector keeps trying
every now and then to connect to the remote server and it sets the value of
oos when it finally succeeds. It does a "synchronized" when it sets the
value of oos. but according to me should the synchronized be on the outer
class SocketAppender instead of connector. In essence, the statement
synchronized(this) should be changed to
synchronized(Connector.this) in my opinion.

but, then again, I may be missing something...

class Connector extends Thread {

    boolean interrupted = false;

    public
    void run() {
      Socket socket;      
      while(!interrupted) {
	try {
	  sleep(reconnectionDelay);
	  LogLog.debug("Attempting connection to "+address.getHostName());
	  socket = new Socket(address, port);

/********The is the statement I am talking about **********/
	  synchronized(this) {
	    oos = new ObjectOutputStream(socket.getOutputStream()); 
	    connector = null;
	    break;
	  }
	}
	catch(InterruptedException e) {
	  LogLog.debug("Connector interrupted. Leaving loop.");
	  return;
	}

Any thoughts?

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org