-
Notifications
You must be signed in to change notification settings - Fork 0
Class Jun
Jun is the class with which you can run a single instance of the application.
This class implements the singleton pattern, so to get the Jun instance you need to use the getInstance()
method.
Example:
Jun.getInstance()
.
View the examples
- void tryLock(String path)
- void unlock(String path)
- void forceLock(String path)
- void tryLock()
- void unlock()
- void forceLock()
throws IOException, ApplicationException, SystemException
This method try to lock the instance. It search in the path of the file passed at the input, to check that there is no other instance running.
Use this at the start of your application.
Parameters:
- path, path to the lock file
Exceptions:
- IOException, exception thrown if an I/O error is returned while working on the file
- ApplicationException, exception thrown if an instance of the application is already running
- SystemException, exception thrown if the searching for the pid return an error
Example:
try { Jun.getInstance().tryLock("file.lock"); } catch (ApplicationException e) { System.out.println("This application is already running."); System.exit(-1); }
This method unlock the file, and allows the execution of a new instance.
Use this method in the final part of the main code.
Parameters:
- path, path to the lock file to be unlocked
Example:
Jun.getInstance().unlock("file.lock");
throws IOException, FileLockException
This method force the lock on the file.
Parameters:
- path, path to the lock file to be forced
Exceptions:
- IOException, exception thrown if an I/O error is returned while working on the file
- FileLockException, exception thrown if an error is returned while locking the file
Example:
Jun.getInstance().forceLock("file.lock");
throws IOException, ApplicationException, SystemException
This method try to lock the instance. It search in the default file, to check that there is no other instance running.
Use this at the start of your application.
The default file is 'single.instance.app' file in the current working directory.
Exceptions:
- IOException, exception thrown if an I/O error is returned while working on the file
- ApplicationException, exception thrown if an instance of the application is already running
- SystemException, exception thrown if the searching for the pid return an error
Example:
try { Jun.getInstance().tryLock(); } catch (ApplicationException e) { System.out.println("This application is already running."); System.exit(-1); }
This method unlock the default file, and allows the execution of a new instance.
Use this method in the final part of the main code.
The default file is 'single.instance.app' file in the current working directory.
Example:
Jun.getInstance().unlock();
throws IOException, FileLockException
This method force the lock on the default file.
The default file is 'single.instance.app' file in the current working directory.
Exceptions:
- IOException, exception thrown if an I/O error is returned while working on the file
- FileLockException, exception thrown if an error is returned while locking the file
Example:
Jun.getInstance().forceLock();