System.out.print Flood Makes DrJava Hang

I just filed a bug report for a serious problem with DrJava that we need to look at. It’s possible to make DrJava hang, or at least slow it down so much that it appears unresponsive, by printing out very long lines without line breaks.

This is related to the problem that Jarred noticed a while back in the DrJava/HJ meeting. Back then, we considered limiting the number of lines stored in the Interactions and Console documents.

I think that’s still a worthwhile idea to pursue, but the problem is more subtle. The same amount of data spread out across several lines, with line breaks inserted, does not make DrJava hang.

This program is bad and causes DrJava to become unresponsive:

[cc_java]public class FloodDrJava {
public static void main(String[] args) {
for(int i=0; i<10000; ++i) { System.out.print("Hello "+i+" "); } } }[/cc_java] This program makes DrJava a bit slow, but it never makes it seem to hang: [cc lang="java"]public class FloodDrJava { public static void main(String[] args) { for(int i=0; i<10000; ++i) { System.out.println("Hello "+i+" "); } } }[/cc] Note that the only difference is [cci]println[/cci] instead of [cci]print[/cci] in line 4. We should actually be sending more characters because of the line breaks.

It may be Swing’s word wrapping or something like that. It really seems to have to do with the length of the lines, and appending at the very end of it. It’s unlikely that simply limiting the number of lines would make a difference here.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in DrJava. Bookmark the permalink.

Leave a Reply