简体   繁体   中英

java Thread doesn't run after 15minutes

does anyone know why the thread does not start right away? that is, 10 min, 20 .. Thread do not start ... logger is simple decorator for java Logger...

here is the code starting:

....
log.info("client streams prepared");
messagelistener = new Thread(new Listener(input, this));
messagelistener.start();
log.info("Connection prepared");
....

and started listener

public class Listener implements Runnable {

    private final MyLogger logger = MyLogger.getLogger();
    private final ObjectInputStream input;
    private final Connection connection;

    public Listener(ObjectInputStream input, Connection callback) {
        connection = callback;
        this.input = input;
        logger.info("Listener created");
    }

    @Override
    public void run() {
        logger.info("listener thread in connection with "+ connection.getUser().getDisplayName() + " is started");
        //.....samecode
        logger.info("listener thread in connection with "
                + connection.getUser().getDisplayName() + " is stopped");
    }
}

logs:

2013-07-29 22:36:58 MyLogger info INFO: client streams prepared  
2013-07-29 22:36:58 MyLogger info INFO: Listener created  
2013-07-29 22:36:58 MyLogger info INFO: Connection prepared

in print see info before start, and after start, but not the first line of the method run, and it's been more than 10 minutes from launch, the system is not loaded, I do not understand why it does not work? someone is able to explain to me what I'm doing wrong?

... and it's been more than 10 minutes from launch, the system is not loaded, I do not understand why it does not work? someone is able to explain to me what I'm doing wrong?

I suspect that the run() method is throwing some sort of exception -- possibly a NPE.

logger.info("listener thread in connection with "+
      connection.getUser().getDisplayName() + " is started");

Any chance that the connection is null or the getUser() returns null here? I bet that if you just log a simple "made it here" method, you will see that in the logs. You should probably enclose the run() lines in a try {} catch (Exception e) { log exception } block and log the exception. I'd also try to use a debugger and put a break point in the first log line and step through it to see what's going on. See this debugging tutorial for eclipse .

You could also set a UncaughtExceptionHandler on your thread to log it that way. See: Using UncaughtExceptionHandler effectively

Another possibility is that your MyLogger is logging the run() log entries into another file but it looks like the main-thread log messages are using the same logger so less likely. If this is possible then using System.out.println("in run()"); at the start of run() will help rule that out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM