Switching between streams in Intellij Idea

How to switch between threads of a paused program?

or Any tutorial on multithreaded debugging with Intellij Idea, describing the main functions - pause, resume, switch between threads.

very good tutorials / walkthroughs for Netbeans: e.g. https://netbeans.org/kb/docs/java/debug-multithreaded.html

+8
debugging multithreading intellij-idea
source share
2 answers

Trick - Set a breakpoint suspension policy to - Thread.

breakpoint properties - suspend policy

After the threads hit the breakpoint and are blocked, the active thread can now be switched to check race conditions / dead ends.

switching between threads

The following code snippet for creating a dead end:

public static void main(String args[]) { Thread thread1 = new Thread(null, new MyThread(obj1, obj2), "Thread-1"); Thread thread2 = new Thread(null, new MyThread(obj2, obj1), "Thread-2"); thread1.start(); thread2.start(); } class MyThread implements Runnable { private Object obj1; private Object obj2; MyThread(Object obj1, Object obj2) { this.obj1 = obj1; this.obj2 = obj2; } @Override public void run() { System.out.println("Acquiring locks"); synchronized (obj1){ System.out.println("Acquired 1st lock"); synchronized (obj2){ System.out.println("Acquired 2nd lock"); } System.out.println("Released 2nd lock"); } System.out.println("Released 1st lock"); } } 
+14
source share

Amit,

You may be interested in an alternative view of call stack threads, which is activated by clicking the Restore Streams button: enter image description here

A bit of documentation around this: Debug Tool Window - Themes

In addition, these questions may be helpful:

  • IntelliJ thread debugging
  • IntelliJ - pause thread while debugging
+5
source share

All Articles