B4J Question Threading library

moore_it

Well-Known Member
Licensed User
Longtime User
Hi all,

i need to put in batch an activity of reading and modifying of thousands photos and i need to see in gui the state of work.
I try this

B4X:
myThread.initialise("THR")
myThread.start(Me,"avvio",Array as string(code))

and have this error in release mode in debug not work

java.lang.IllegalStateException: Not on FX application thread; currentThread = THR

how i do ?

Thanks
 

moore_it

Well-Known Member
Licensed User
Longtime User
This is the code :

B4X:
For i = 0 To foto.Size - 1
            ' controllo invio foto
            Dim found As Int
            found = dbdata.ExecQuerySingleResult("Select count(*) from sended where d01 = '"&code&"' and d02 = '"&foto.Get(i)&"'")
            If found = 0 Then
                ' load immagine
                img.Initialize(pathfoto,foto.Get(i))
                c.SetSize(img.Width,img.Height)
                c.DrawImage(img,0,0,img.Width,img.Height)
                ' put watermark
                c.DrawImage(wtr,100,(img.Height-wtr.Height)/2,wtr.Width,wtr.Height)
                c.DrawImage(wtr,img.Width-(wtr.Width+100),(img.Height-(wtr.Height*2.5)),wtr.Width,wtr.Height)
                'write immagine
                Dim out As OutputStream = File.OpenOutput(File.DirTemp&"FotoWatermark","base.png",False)           
                c.Snapshot.WriteToStream(out)
                out.close
                ' from png to jpg
                Dim png4jpg As pngTojpg
                png4jpg.convert(File.DirTemp&"FotoWatermark\base.png",File.DirTemp&"FotoWatermark\"&foto.Get(i) )
                ' write sended table              
                Try
                    dbdata.BeginTransaction
                    DateTime.DateFormat = "yyyyMMdd"
                    dbdata.ExecNonQuery("Insert into SENDED(ID,D01,D02,D03,D04,D05,D06,D07,D08,D09,D10,T01) values(null,'"&code&"','"&foto.Get(i)&"','"&DateTime.Date(DateTime.Now)&"','','','','','','','','')")       
                    dbdata.TransactionSuccessful
                Globals.count = Globals.count + 1
                Dim Params(1) As Object
                Params(0) = Globals.count
                OK = False
                Do Until OK
                    Thread1.RunOnGuiThread("Update", Params)
                    OK = Lock1.WaitFor(1000)
                Loop   
                Catch
                    Log(LastException)
                End Try
            End If
 
    Next


And this is the error

(IllegalStateException) java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread1

Thanks for your help !
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
This part :

B4X:
 c.Snapshot.WriteToStream(out)

generate this error

(IllegalStateException) java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread1
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
The way I would do it is to create a separate JAR that modifies one image at a time. Call this JAR with the path of the image as the argument (arg()) and process the image.

Then in the main application, create a list of paths to process with jShellQueue, call the JAR for each path, set the maximum number of threads running at the same time, and process the queue.
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
Please Jmon how i do to run an .jar with parameters ?
try this but nothing happend

B4X:
queue.AddToQueue( "jCreaFoto.jar",Array As String(pathwatermark, pathfoto,code, foto.Get(i)),File.DirApp,False,"")

thanks i advice
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
ok found but how i do to retrive the parameters of the .jar app ?

B4X:
queue.AddToQueue("java.exe",Array As String("-jar","jCreaFoto.jar",pathwatermark, pathfoto,code, foto.Get(i)),File.DirApp,False,"")

thanks
 
Upvote 0
Top