In intellij 2020.1, when I hit play in debugger, how to stop it from switching threads? (not duplicate) - intellij-idea

I perhaps was not clear enough in this question
https://stackoverflow.com/questions/62958507/how-to-have-intellij-play-just-the-thread-i-am-debugging-like-eclipse-does
so it was marked as duplicate of
switching between threads in Intellij Idea
but I did that and changed my breakpoint suspend policy to 'Thread'. This did not change the behavior at all so I am providing code now here.
Here is my code for this test
public class TestDebugger {
private static final Logger log = LoggerFactory.getLogger(TestDebugger.class);
private Executor exec = Executors.newFixedThreadPool(5);
public static void main(String[] args) throws InterruptedException {
new TestDebugger().start();
Thread.sleep(10000000);
}
private void start() {
Runnable r = new Runnable() {
#Override
public void run() {
log.info("logger BREAKPOINT A thread="+Thread.currentThread().getName());
log.info("logger A");
log.info("logger A");
log.info("logger A");
log.info("logger A");
log.info("logger A");
log.info("logger A");
log.info("logger BREAKPOINT B"+Thread.currentThread().getName());
}
};
exec.execute(r);
exec.execute(r);
exec.execute(r);
}
}
I start up the program and threads 1,2,3 all stop on breakpoint A. This part is good. Then I hit the play button while on thread 1 and behind my back, it switches threads!!! This is very annoying and not desired. In fact, I feel the eclipse debugger here works MUCH better as that is the default behavior.
In fact, if I hit play 6 times for all 3 threads, this is the logs...
NOTE: If I remove the other log statements in the middle, it starts working again as I would expect.......weird
INFO: logger BREAKPOINT A thread=pool-2-thread-1
INFO: logger BREAKPOINT A thread=pool-2-thread-3
INFO: logger BREAKPOINT Bpool-2-thread-3
INFO: logger BREAKPOINT Bpool-2-thread-1
INFO: logger BREAKPOINT A thread=pool-2-thread-2
INFO: logger BREAKPOINT Bpool-2-thread-2
The first TWO logs should both be thread 1 but instead it's thread 1, then thread 3....grrrr. Anyway to get this to work?
thanks,
Dean

This behavior is by design and there is no way to change it at the moment. Source: developer responsible for IntelliJ IDEA debugger.

Related

.netcore webapi debugging pause

I have a web api project which is a console application and the main looks like
public static void Main(string[] args)
{
// Get the current settings.
ThreadPool.GetMinThreads(out var minWorker, out var minIOC);
// Change the minimum number of worker threads to four, but
// keep the old setting for minimum asynchronous I/O
// completion threads.
if (ThreadPool.SetMinThreads(250, minIOC))
{
Logger.Info("The minimum number of threads was set successfully");
}
else
{
Logger.Error("The minimum number of threads was not changed");
// The minimum number of threads was not changed.
}
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>().Build();
}
When the debugger runs and paused it's always this line that is hit:
BuildWebHost(args).Run();
How do I make it pausing at the actual code being executed?
Edit
I'm pressing pause while some request is being executed and expect to see, for example, a call to the database when paused
While debugging open threads window (Debug->Windows->Threads). Once paused one of those threads will be the right worker with required call stack.

Debugging charm projects in Netbeans

I'm trying to debug a charm project. I've set break points in the code, but each time execution reaches a break point, Netbeans freezes and I'm obliged to forcefully close it.
For what it's worth, I'm using Ubuntu 15.04
[Edit 1]
Here's an image of a set break point
I am getting an exception:
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException
that doesn't point to any line in my code, so I want to debug and get what is causing the problem. Immediately the code gets to line 106, everything freezes.
[Edit 2]
Ok here's most of the controller code.
public void initialize(URL url, ResourceBundle rb) {
departmentList.setPlaceholder(new Label("Oops!! EMPTY!!!"));
/*
Populate SideMenu
*/
ObservableList<Label> schools = FXCollections.observableArrayList();
ListView<Label> schoolList = new ListView<>(schools);
for (School school : schoolsList) {
schools.add(new Label(school.getName(), MaterialDesignIcon.ACCOUNT_BALANCE.graphic()));
}
/*
Add Listeners to side Menu ListView
*/
schoolList.getSelectionModel().selectedItemProperty().addListener(
(ObservableValue<? extends Label> observable, Label oldValue, Label newValue) -> {
selectedSchool = parser.findSchool(newValue.getText());
loadDepartments();
MobileApplication.getInstance().hideLayer("Side Menu");
});
/*
Add Listener to departments ListView
*/
departmentList.getSelectionModel().selectedItemProperty().addListener(
(ObservableValue<? extends Label> observable, Label oldValue, Label newValue) -> {
if (newValue == null) {//Got fired by clearing the Observable list
return;
}
System.out.println(newValue);
facDept[1] = newValue.getText();
/*
Reset before leaving; *to be removed and tried on mobile
*/
loadDepartments();
MobileApplication.getInstance().switchView(SEMESTER_VIEW);
});
borderPane.setCenter(schoolList);
center.getChildren().add(departmentList);
}
#FXML
private void showLayer(ActionEvent event) {
MobileApplication.getInstance().showLayer("Side Menu");
}
I set a break point in the showLayer method(MobileApplication...), and debugging works. I set another one the line selectedSchool = parser.findSchool(newValue.getText());, but here debugging freezes. Note that the exception doesn't occur here.

Titanium module - life cycle events not called

I am building a Titanium module for the Android platform and I want to use the life cycle events of the module (i.e. onDestroy, onPause, etc). I tried to use them by overriding these life cycle events in the module class like this:
#Kroll.module(name="custom", id="vub.ac.be.custom")
public class CustomModule extends KrollModule {
private static final String TAG = "customModule";
#Kroll.onAppCreate
public static void onAppCreate(TiApplication app) {
}
private void destroyServices(){
//...
}
#Override
public void onStop(Activity activity) {
Log.d(TAG, "STOPPING");
destroyServices();
super.onStop(activity);
}
#Override
public void onPause(Activity activity) {
Log.d(TAG, "[MODULE LIFECYCLE EVENT] pause");
super.onPause(activity);
}
#Override
public void onResume(Activity activity) {
Log.d(TAG, "[MODULE LIFECYCLE EVENT] resume");
super.onResume(activity);
}
#Override
public void onDestroy(Activity activity) {
Log.d(TAG, "[MODULE LIFECYCLE EVENT] destroy");
destroyService();
super.onDestroy(activity);
}
}
but when I opening and closing the application, these life cycle events are never called. Does anybody know how to use them, because only if I can use them I will be able to build the module I want. Thanks
Could this be the origin of my problems: inline link moddevguide
https://github.com/appcelerator/titanium_modules/blob/master/moddevguide/mobile/android/src/ti/moddevguide/ModdevguideModule.java
on line 72 they describe the following:
// Lifecycle
// NOTES:
//
// 1. Modules are created in the root context
// 2. Using navBarHidden (or fullscreen or modal) causes the window, when opened, to run in a new Android Activity.
// 3. The root context/activity will be stopped when a new activity is launched
// 4. Lifecycle notifications will NOT be received while the root activity is stopped.
I run the module in an application that uses navBarHidden, so as described a new android activity wil be started and the root activity is stopped. Whenever the root activity is stopped, the lifecycle notifications are received. Can anyone confirm this and does anybody know how to solve this? thanks
What version of SDK are you using? On 3.3.0 lifecycle callbacks is calling regardless to navigation bar hidden.

eclipse java multithread program debugging

while debugging the java Multithreading program i put breakpoints. after start method is invoking the control is not going to run menthod can you please let me know the debug procedure.
sample code
class Test extends Thread {
public static void main(String[] args) {
try {
Thread t = new Thread(new Test());
t.start();
t.start();
} catch (Exception e) {
System.out.print("e ");
}
}
public void run() {
for(int i = 0; i < 2; i++)
System.out.print(Thread.currentThread().getName() + " ");
}
}
Debugger starts with main thread, since your breakpoint is in main thread.
t.start() spawns a new thread.
But the debugger will continue with the main thread itself.
If you want to debug the newly created thread, then you have to set a breakpoint in run() method also.Then the debugger control goes to the newly created thread, but it is invisible to the user.
If you want to see the control in run() method of newly created thread, then you have to follow the below steps -
Put a breakpoint in run() method along with the main() method.
Start debugging the program till you hit the statement t.start().
After completing t.start(), go to "Debug" view. There you will find 2 threads running.(You can find the "Debug" view in eclipse by going to "Window -> Show View -> Debug").
First one is main thread
Second one is newly created thread (e.g. [Thread-1] )
Click on the second thread to see the control in run method.
After completion of your thread execution, go to the "Debug" view again and click on the main thread to continue with the main thread debugging.
Note: If you continue with the main thread after 3rd step towards the end of the thread, then you will not be able to debug your new thread.

IntelliJ sometimes does not respect breakpoints

I have the following code:
/*01*/ final BlockingQueue<CsvFileRow> allRows = new LinkedBlockingQueue<CsvFileRow>();
/*02*/ ExecutorService exec = Executors.newFixedThreadPool(3);
/*03*/ Callable<Void> producer = new Callable<Void>() {
/*04*/ #Override
/*05*/ public Void call() throws Exception {
/*06*/ System.out.println("Before producer");
/*07*/ produceDataRows(allRows);
/*08*/ System.out.println(" After producer");
/*09*/ return null;
/*10*/ }
/*11*/ };
/*12*/ Callable<Void> consumer = new Callable<Void>() {
/*13*/ #Override
/*14*/ public Void call() throws Exception {
/*15*/ System.out.println("Before consumer");
/*16*/ consumeDataRows(allRows);
/*17*/ System.out.println(" After consumer");
/*18*/ return null;
/*19*/ }
/*20*/ };
/*21*/ exec.submit(producer);
/*22*/ exec.submit(consumer);
/*23*/ exec.shutdown();
/*24*/ exec.awaitTermination(10, TimeUnit.DAYS);
/*25*/ assert Boolean.TRUE;
I have breakpoints on lines 7, 16, 21 and 25. Running the code stops on the breakpoints 21,7 and then 25 - the breakpoint 16 is skipped! But, the code has been executed, see the output:
Before producer
Before consumer
After consumer
After producer
Now, if I remove the breakpoint 7, then the debugger stops on the breakpoints 21,16 and then 25.
This is an extremely annoying issue. In fact, there are other scenarios where I have noticed that IntelliJ ignores the breakpoints, which is very disturbing.
Am I missing something?