JConsole does not connect when a program is waiting for a console input

Posted by Calm Storm on Stack Overflow See other posts from Stack Overflow or by Calm Storm
Published on 2010-03-15T13:54:08Z Indexed on 2010/03/15 14:29 UTC
Read the original article Hit count: 374

Filed under:
|
|

Hi, I have a problem similar to the one mentioned here. I have a program which launches a selenium browser and refreshes it every 2 seconds. My idea here was to monitor the memory usage of my application as the page is being hit. This console program does a "System.in.read" and when a user presses enter key, this stops the browser refresh thread. I run the program and it runs as I would expect it to. But when I fire jconsole and attach it to the process, it looks like jconsole waits forever to attach. This is because of the "System.in.read", apparently as shown in the JConsole source. In my code it makes perfect sense for me to terminte the browser when user presses something so is there any alternative available at all ? (Posted code sample below)

package com.ekanathk;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class MultiThread {

    @Test
    public void testSimple() throws Exception {
        List<Integer> x = new ArrayList<Integer>();
        for(int i = 0; i < 1000; i++) {
            x.add(i);
        }
        System.out.print("Press Enter to stop (try attach a jconsole now....");
        System.in.read();
    }
}

The problem here seems to be that any System.in.read (either in Main thread or any threads) seems to completely block jconsole. I guess the problem essentially boils down to multiple threads requesting system inputs at the same time? Is there a solution ?

© Stack Overflow or respective owner

Related posts about jconsole

Related posts about java