Monitor file to find which thread is modifying file
I want to find which java thread is modifying file. If anybody know tool or know how we can monitor and get thread name please share.
I am not sure why exactly you need this information but i beleive there are two ways.
First way is in your java code when you create a thread , create it with a name. There are constructors & method available in Thread class to do the same. If you have a good logging in your project then you can log the thread name who enters the code to modify the file.
Second way is again dependent on having a thread with the name. You can use a java profiler to find out what threads are doing at a point in time. Although it will be too tough if threads are modifying the file too quickly. But if you are trying to find a problem of slow modification of file by a thread then profiler may give you the hint.
Hope it helps!
if the file modification is a code that you wrote, you can use before the modification:
and youl get the name and id of the thread