B4J Question Check if the .jar is already runing

Douglas Farias

Expert
Licensed User
Longtime User
Hi all
how can i check if my .jar is runing already?
for example if the user open my .jar and already is runing, show a msg, this is runing you cant open another.

thx
 

Roycefer

Well-Known Member
Licensed User
Longtime User
When the .jar first starts up, check for a file called "running.txt". If it doesn't exist, create it. If it does exist, post a message saying "can't have two instances of this app running" and then shutdown. When the user closes the app, don't forget to delete "running.txt".
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
any other way? for example check on taskmanager (system process) if this is running and show a msg?
i already have this ideia of txt file, but i remember the user can use ALT + F4 and i cant delete txt in this case :)
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
All java processes show up as java.exe in the Task Manager. That won't be of any use to you. Erel had the idea to open up a Socket on (say) port 12345. Attempting to open a socket on this port will fail if another program has already opened a socket on that port. Ideally, the port should be released when the process ends, regardless of how it ends, but I would test that to make sure.
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
I use a SQLite file.

B4X:
TempPath = Utils.GetCanonicalPath (File.DirTemp)
lbInfo.Text = "Deleting old database"
If File.Exists (TempPath, "Databs.db") Then
    If Not (File.Delete (TempPath, "Databs.db")) Then
        msgbox.show ("Databs.db is in use. Stopping system.")
        ExitApplication
    end If
end If
CallSubDelayed (Me, "IniSql") 'create and initialize the file Databs.db
 
Last edited:
Upvote 0
Top