log4j and threading

B

bigbinc

Is log4j really thread safe. I have an object that contains a thread,
the thread contains log4j logging code, when I kill the object and
kill the thread....and then restart the thread, it seems like the
thread is still active because log4j is still logging for the dead
thread? Has anyone had this problem? Is it my threading or log4j.

My thread just has a run()

while(running) {
}


and when I kill threads, start threads, log4j prints information from
20-30 dead threads, even though I should have 1 - 2 open.
 
C

Christophe Vanfleteren

bigbinc said:
Is log4j really thread safe. I have an object that contains a thread,
the thread contains log4j logging code, when I kill the object and
kill the thread....and then restart the thread, it seems like the
thread is still active because log4j is still logging for the dead
thread? Has anyone had this problem? Is it my threading or log4j.

My thread just has a run()

while(running) {
}


and when I kill threads, start threads, log4j prints information from
20-30 dead threads, even though I should have 1 - 2 open.

Threads can't be killed or restarted. A thread stops once it exits the run
method. How exactly are you "killing" and "restarting" those threads?
 
B

bigbinc

Christophe Vanfleteren said:
Threads can't be killed or restarted. A thread stops once it exits the run
method. How exactly are you "killing" and "restarting" those threads?



Lets I have an object

AThread extends Thread () {
run() {
while(running){}
}
}

Obj {
AThread thread = AThread()

thread.start()

public void shutdown() {

thread.callMyShutdownMethod() { running = false }
thread = null;
}

}


Obj o = new Obj();

o.shutdown()

o = null

o = new Obj();
o.shutdown
o = null

o = new Obj();
o.shutdown
o = null

Are you telling me the code above, leaves the threads open.
 
V

Virgil Green

bigbinc said:
Christophe Vanfleteren <[email protected]> wrote in message



Lets I have an object

AThread extends Thread () {
run() {
while(running){}
}
}

Obj {
AThread thread = AThread()

thread.start()

public void shutdown() {

thread.callMyShutdownMethod() { running = false }
thread = null;
}

}


Obj o = new Obj();

o.shutdown()

o = null

o = new Obj();
o.shutdown
o = null

o = new Obj();
o.shutdown
o = null

Are you telling me the code above, leaves the threads open.

I'll tell you that none of that code even compiles. There's no way to tell
if the representative code above represents what you are actually
experiencing. Post a complete example that will compile and that
demonstrates the problem. Write to stdout rather than a log and show that
the output continues after you think you have shutdown.

- Virgil
 
B

Berlin Brown

That is better, not on google groups.

Yea, it has to be log4j, still keep the thread around or something. I dont
have a complete example that isnt a bunch of a code, this might work.

public class X extends Thread {
Logger log = Logger.getClass(X.class);
public void run(){log.info("hello"); while(running);}
public void shutdown(running=false;}
}

public class Y {
X x = new X();
Y() { x.start(); }
public void shutdown(){x.shutdown(); x = null;}
}

public class Z {
public static void main(String [] args) {
Y y = new Y();
y.shutdown();
y = null;

y = new Y();
y.shutdown();
y = null;
}
}


the 'hello' code above for example will show several times meaning that
threads arent closing? I could be wrong.

This is pseudo code.
 
B

Berlin Brown

Berlin said:
That is better, not on google groups.

Yea, it has to be log4j, still keep the thread around or something. I
dont have a complete example that isnt a bunch of a code, this might work.


The threading doesnt have any extra debugging info using only
System.out.println, but using the logger system, I get weird results. I am
just going to assume that the logger doesnt release its attachment to a
thread, depending on certain conditions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

log4j configuration and Applets 15
log4j, threading and appenders 3
threading 1
log4j/commons-logging issue? 3
log4j multiple appenders 3
Class Loader, Class and Object 0
tomcat log4j 3
Log4j wrapper 3

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top