JDK-4492918 : TTY: debugee output not seen until a newline is written
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: generic
  • Submitted: 2001-08-16
  • Updated: 2002-09-06
  • Resolved: 2002-09-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 beta3Fixed
Related Reports
Relates :  
Description
Message from Apple below shows on a test example that JDB stops printing
output of multi-threaded application. Needs to be fixed. PLease see
below.

Message from Apple:
===================

I have a test program that contains a main thread, and another thread named "SpawnedThread". Each thread waits five seconds then prints some diagnostic output. The main thread prints dots, "SpawnedThread" prints integers starting at 0.

Here is the test case:

NewThread.java:
public class NewThread
{
    public static void main(String[] args) {

        System.out.println("Spawning a new thread in 10 seconds");

        long startTime = System.currentTimeMillis();

        while(System.currentTimeMillis() < startTime + 10000)
        {
                //wait
        }

        Thread t = new SpawnedThread("Spawned Thread");
        t.start();

        System.out.println("Thread spawned.");

        long lasttime = 0;
        while(true)
        {
            if(System.currentTimeMillis() > lasttime + 5000) {
                lasttime = System.currentTimeMillis();
                System.out.print(".");
            }
        }
    }
}

SpawnedThread.java:
public class SpawnedThread extends Thread
{
        public SpawnedThread(String name)
        {
                super(name);
        }

        public void run()
        {
            int a = 0;
            long lasttime = 0;

            while(true)
            {
                if(System.currentTimeMillis() > lasttime + 5000) {
                    System.out.print(a++);
                    lasttime = System.currentTimeMillis();
                }
            }
       }
}

When the program runs with the normal java command, it prints "Spawning a new thread in 10 seconds". After 10 seconds elapse, it prints "0Thread spawned." The '0' is the first output from the spawned thread. After five more seconds, the seperate threads start send their output in five second intervals. The main thread prints '.', and SpawnedThread prints integers. So, the rest of the output looks like '.1.2.3.4.5' (ad infinitum)  When the program runs under jdb, it prints "VM Started: Spawning a new thread in 10 seconds". After 10 seconds elaps, it prints "0Thread spawned." Subsequent output from the program never shows up. Using different jdb commands, it's apparent that the threads are still running, but the output is nowhere to be seen.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta3 FIXED IN: merlin-beta3 INTEGRATED IN: merlin-beta3
14-06-2004

EVALUATION ###@###.### 2001-08-17 This is not a threading problem. When jdb is started using a launching connector, as is used while processing a command like "jdb myClass", jdb can get the out/err streams from the debugee Process object. The debugee output streams are read and transferred to jdb's output via readLine()/println() calls. This is possible only when using the launching connector, and works only when the debugger and debugee are both running on the same machine. (See Bug-ID 4362594) Since the test case on this bug does not print any newlines after initialization/startup, the readLine() in jdb does not return and you don't see the output. Here is a simplified test case: public class Out { public static void main(String[] args) { System.out.println("Starting up"); int a = 0; while(true) { try { Thread.sleep(5 * 1000); System.out.print("."); } catch (InterruptedException e) { e.printStackTrace(); } try { Thread.sleep(5 * 1000); System.out.print(a++); } catch (InterruptedException e) { e.printStackTrace(); } if ((a % 10) == 0) { System.out.println(); } } } } When this program is run under jdb, you will see the debugee output a line at a time after the System.out.println() is executed.
11-06-2004

WORK AROUND ###@###.### 2001-08-16 To bypass this conflict, separate debugger and debugee. Start the debugee program in one command window: java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=4571 NewThread Start jdb in another window and attach to the debugee via a socket: jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=4571 You may also use the shared memory transort if you are on a win32 platform, as follows: In one command window: java -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,address=mine NewThread In a second command window: jdb -connect com.sun.jdi.SharedMemoryAttach:name=mine
11-06-2004

SUGGESTED FIX ###@###.### 2001-08-22 % sccs diffs -r 1.1 MessageOutput.java ------- MessageOutput.java ------- 2c2 < * %W% %E% --- > * @(#)MessageOutput.java 1.2 01/08/22 30c30 < * @version %Z% %M% %I% %E% %T% --- > * @version @(#) MessageOutput.java 1.2 01/08/22 17:15:25 95a96,98 > static void printDirect(char c) { > System.out.print(c); > } % sccs diffs -r 1.37 VMConnection.java ------- VMConnection.java ------- 2c2 < * %W% %E% --- > * @(#)VMConnection.java 1.38 01/08/22 276,278c276,278 < String line; < while ((line = in.readLine()) != null) { < MessageOutput.printDirectln(line);// Special case: use printDirectln() --- > int i; > while ((i = in.read()) != -1) { > MessageOutput.printDirect((char)i);// Special case: use printDirect()
11-06-2004

PUBLIC COMMENTS .
10-06-2004