mbauer
mbauer

Reputation: 345

How to check if eclipse workspace is locked

I have several eclipse instances running at the same time and I want to check if a workspace from one of these instances is currently in use. So I want to check it with just the knowledge of the path C:\Users\XY\workspace to the workspace.

I've seen that there is a .lock file in the .metadata folder. But its size is all the time 0 KB. So how to check it?

Thanks in advance!

Upvotes: 1

Views: 769

Answers (1)

greg-449
greg-449

Reputation: 111142

The locking code org.eclipse.osgi.internal.location.Locker_JavaNio uses:

RandomAccessFile raFile = new RandomAccessFile(lockFile, "rw");

FileLock fileLock = raFile.getChannel().tryLock(0, 1, false);

to lock the .lock file.

The tryLock will throw an exception if the file is already locked.

Unlock is:

fileLock.release();

raFile.close();

Upvotes: 1

Related Questions