B4J Question Autorestart B4J application ?

marcick

Well-Known Member
Licensed User
Longtime User
I have problems that need to be investigated, for some reasons after some days the app does not behave correctly.
In the specific, the app is a JRDC2 server that send notifications to IOS devices throught Apple service.
What happens, after some days, is that the notification looks like succesfully sent but does not arrive. Restarting the app all works again.

What I would like to do for now, is that the app restart itself every day for example. Is that possible to implement ?
 

marcick

Well-Known Member
Licensed User
Longtime User
mmmhhh ..... not perfect, but sure I'm wrong somewhere

This is my test program

B4X:
Sub Process_Globals
    Private robot As AWTRobot
    Private tmr1 As Timer
End Sub

Sub AppStart (Args() As String)
    tmr1.Initialize("tmr1",5000)
    tmr1.Enabled=True 
    Log("Start")
    StartMessageLoop
End Sub

Sub tmr1_tick
    robot.relaunchSelfbatch("test.bat")
End Sub

test.bat file is inside object folder and contains "java -jar test.jar"

But after 5 seconds it is not launched again.
Where I'm wrong ?

If I use this instead, it works but the console does not appear

B4X:
Sub tmr1_tick
    robot.relaunchSelf("test.jar", "")
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can create a batch file that sleeps for a few seconds and then starts the jar with the start command: http://stackoverflow.com/a/15549987/971547
Sleep: https://serverfault.com/a/432323

Run it with jShell and then call ExitApplication.

I'm not 100% sure whether the batch file will be killed or not when you call ExitApplication. You need to test it. It will probably work fine.

If it is killed then the solution is to use a timer when jRDC2 starts and only call srvr.Start after a few seconds. This will allow the old program to call the batch file, wait for it to complete and then call ExitApplication.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
not clear how to implement it .....
But I suppose this code should work, Am I wrong somewhere ?

B4X:
Code:
Sub Process_Globals
    Private robot As AWTRobot
    Private tmr1 As Timer
End Sub

Sub AppStart (Args() As String)
    tmr1.Initialize("tmr1",5000)
    tmr1.Enabled=True
    Log("Start")
    StartMessageLoop
End Sub

Sub tmr1_tick
    robot.relaunchSelfbatch("test.bat")
End Sub


test.bat file is inside object folder and contains "java -jar test.jar"
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I've uploaded a new jAWTRobot library version (1.54) that includes a bug fix for this.

mmhhh ....
robot.relaunchSelfbatch works now but leave each time a console window open.
robot.relaunchSelf works but there is no console window on relaunch.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
I don't understand. Do you or do you not want a console window? Calling "javaw -jar test.jar" will typically run your program without a console window. "java -jar test.jar" will run it with a console window.

Cool tip: call "exit" at the end of your batch file to close the console window associated with the last instance of your app:
B4X:
java -jar test.jar
timeout 5
exit
 
Last edited:
Upvote 0
Top