B4J Question non-ui app problem

tufanv

Expert
Licensed User
Longtime User
Hello,

I have a b4j non-ui app working 24 hours on vps to update mysql db every 5 seconds according to data downloaded from remote server. LAtely it started to stop randomly with crash. I removed obfuscation and started with nohup on my vps.

Last night it crashed again and the sub it crashed was appstart.

How can a 24 hour running app go to appstart and crash there ? ( It was running for more than 24 hours when it crashed )

What may i be doing wrong , how the the already ruuning app go to appstart ?

error was saying for the appstart : java.null.pointer.exception.

I have these on my appstart :

B4X:
Sub AppStart (Args() As String)


    
 

    timerayarla
    veri_al
    StartMessageLoop

 
End Sub

B4X:
Sub timerayarla
    timeryenile.Initialize("timeryenile",1500)
    timeryenile.Enabled=False
    timerlog.Initialize("timerlog",1)
    timerlog.Enabled=False
End Sub

B4X:
Sub veri_al
ob
    j.Initialize("j", Me)
    j.Download("http://....")
End Sub


Thanks
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Everything that runs in the Main Thread will run inside StartMessageLoop which is called from AppStart. You should post the whole stack trace.

You might want to take a look at the jAWTRobot library. It allows you to use a protected Message Loop that can recover from Exceptions while still giving you all the info about the Exception.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
timeryenile.Initialize("timeryenile",1500)
timeryenile.Enabled=
False
timerlog.Initialize("timerlog",1)
timerlog.Enabled=
False
I'm going to guess that the timers are enabled somewhere else? You have a 1 millisecond timer for logging? May be excessive? Also, your other timer is 1.5 seconds, not 5 seconds (may just be the sample here). With those two timers and a combination of downloading from the web, updating a SQL file, there may just not be enough time between ticks. Could try to set a global busy flag and use it in the sub veri_al to skip its processing if it is already processing:
B4X:
Sub veri_al
  if busy = false then
    busy = true
    j.Initialize("j", Me)
    j.Download("http://....")
    busy = false
  end if
End Sub
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Remember that all these event subs are executed in the Main Thread which means that there will be no simultaneous execution of these subs.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Remember that all these event subs are executed in the Main Thread which means that there will be no simultaneous execution of these subs.
Novice mistake. Plus I misunderstood timers, thinking that they work like interrupts. Therefore I was thinking that the 1 for the logging timer would flood something out, but it does not. The documentation for timers states
that the timer events will not fire while the UI thread is busy running other code
and I'm guessing this applies to the main thread of a non-ui app as well (a small test program seems to confirm that).
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
error is :

B4X:
main._appstart (java line: 50)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:489)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:460)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:534)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:146)
    at b4j.example.main._appstart(main.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.main(main.java:29)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:480)
    ... 13 more
Caused by: java.lang.NullPointerException
    at b4j.example.callsubutils._plusimpl(callsubutils.java:102)
    at b4j.example.callsubutils._callsubplus2(callsubutils.java:78)
    at b4j.example.callsubutils._callsubplus(callsubutils.java:71)
    at b4j.example.main._jobdone(main.java:91)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    ... 14 more
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Can you post the code in Main.JobDone?

Note that there is no reason to use CallSubPlus. Remove it and use Sleep instead.
Hello,

I've disable callsubplus

this is jobdone :

B4X:
Sub JobDone(Job As HttpJob)

   
   
    If Job.JobName="j" Then
        If Job.Success Then
'            Log(Job.GetString)
            Dim anne As String = Job.GetString
            '    Log(Job.GetSize/1000)
               
       
   
   
   
'            timerlog.Enabled=True
           
            Dim yolla2 As HttpJob
            yolla2.Initialize("datayolla3", Me)
            yolla2.PostString("http://...","action=1&data="&anne)
            yolla2.GetRequest.Timeout=3000
               
            'tbldata icin icin
            Dim yolla As HttpJob
            yolla.Initialize("datayolla", Me)
            yolla.PostString("http://...","action=1&data="&anne)
            yolla.GetRequest.Timeout=3000
               
            'tblson icin
            Dim yolla2 As HttpJob
            yolla2.Initialize("datayolla2", Me)
            yolla2.PostString("http://...p","action=1&data="&anne)
            yolla2.GetRequest.Timeout=3000
           
            'home server için

   
   
            'yolla.download2("http://...", Array As String ("action", "1", "data",anne))
           
       
        Else
            veri_al
            Log("basarisiz1")
           
        End If

    End If
   
    If Job.JobName="datayolla" Then
        Try
        If Job.Success Then
'            Log("Success2. Datetime:")

'                timeryenile.Enabled=True
        Else
            Log("Failed2. ")
           
'                Dim yolla As HttpJob
'                yolla.Initialize("datayolla", Me)
'                yolla.PostString("http://...","action=1&data="&anne)
'                yolla.GetRequest.Timeout=3000
               

            '                yolla.GetRequest.Timeout=5000
           

                       
                       
        End If
        '            Log(Job.GetString)
       
        Catch
            Log(LastException)
            End Try
           
    End If
   

    If Job.JobName="datayolla2" Then
        If Job.Success Then
'            Log("success3")
           
            timeryenile.Enabled=True
       
        Else
            Log("Failed3")
            Dim yolla2 As HttpJob
            yolla2.Initialize("datayolla2", Me)
            yolla2.PostString("http://...","action=1&data="&anne)
            yolla2.GetRequest.Timeout=3000
       


           

                       
                       
        End If
        '            Log(Job.GetString)
       
       
           
    End If
    If Job.JobName="datayolla3" Then
        If Job.Success Then
'            Log("SuccessEV.")
       
        Else
            Log("Failed.EV")
       


           

                       
                       
        End If
        '            Log(Job.GetString)
       
       
           
    End If
    Job.Release
   

   
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
creating a timer in the AppStart will NOT run in a seperate thread?
With the exception of server solutions, all events are raised on the main thread.

In server solutions the events in handler classes are raised on the handler thread. In other modules (such as the Main module) they are raised on the main thread.
Background worker classes behave like handler classes.
 
Upvote 0
Top