简体   繁体   中英

Java Multithreading Exception Scenarios

I am a beginner and trying to learn java.I have below situation and trying to get some suggestions. If there is an error with java multi threading, what are the steps to debug the issue? For example: There is a instance variable where multiple threads are acting on it. Variable is not declared as volatile. As per my understanding, in this case variable will be cached in local memory of thread and read from there. This will lead to data inconsistency. How do we debug this kind of situation? In other words, how can we find out where exactly in the code, the error is occurring?

One of the best ways to debug in java, especially for threads, is to use breakpoints . You can, like some comments suggest, use sysout statements in your code that fire when a condition is met. In the future, try to post some short, runnable code that gives us some idea of what exact problem you are having. It is impossible to tell you how to troubleshoot something if we don't know what your problem is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM