- A Concurrent Affair - https://www.concurrentaffair.org -

System.out.print Flood Makes DrJava Hang

I just filed a bug report for a serious problem with DrJava [1] 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:

1
2
3
4
5
6
7
public class FloodDrJava {
  public static void main(String [2][] args) {
    for(int i=0; i<10000; ++i) {
      System [3].out.print("Hello "+i+" ");
    }
  }
}

This program makes DrJava a bit slow, but it never makes it seem to hang:

1
2
3
4
5
6
7
public class FloodDrJava {
  public static void main(String [2][] args) {
    for(int i=0; i<10000; ++i) {
      System [3].out.println("Hello "+i+" ");
    }
  }
}

Note that the only difference is println instead of print 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.

[4] [5]Share [6]