Thanks for your info
B4A code runs on a single thread. Some of the libraries do work in a background thread.
You make a confusion between "multicore" and "multithreading". On all Android devices, many threads are run on the same core. That does not make things faster. That just gives the feeling that some things are run in parallel (but of course they're not). That won't change anything to your need. What you need is to run these threads in their own core for a true parallelism. In most cases, it's the OS or the CPU itself that decides the allocation. I don't know if you can force it on Android, but usually it's done in a very efficient way so you don't have to worry.I am afraid, on my case although SQL library supports asynchronous queries, this may not enough.
Here is the sample case.
I have local sqlite table that need to update its values from web server on a periodically basis.
Table structure like this (this is just a sample, actual structure is more complex)
- Id int primary key
- Field1 int
Table has about 20000 records and growing.
The procedure is simple, get Field1 value on web server (via RDC) base on Id then update it to local sqlt table.
Since no multi thread supported, app must loop into 20000 records for download and update process.
If multi thread supported, I can create, may be 10 threads, each thread only need to handle 2000 records.
I thought, based on link you gave me, core allocation is done on Android OS, developer can only tried to do multi thread for better performance. May be I was misunderstoodYou make a confusion between "multicore" and "multithreading". On all Android devices, many threads are run on the same core. That does not make things faster. That just gives the feeling that some things are run in parallel (but of course they're not). That won't change anything to your need. What you need is to run these threads in their own core for a true parallelism. In most cases, it's the OS or the CPU itself that decides the allocation. I don't know if you can force it on Android, but usually it's done in a very efficient way so you don't have to worry.
Oh course there is multithreaded support, but in my case, not sure.It is not correct that there is no multithreaded support.
RDC (which is based on HttpUtils2) is handled by a pool of background threads. The same is true for the asynchronous SQL methods.
You need to fetch all the data and then insert it with SQL.ExecNonQueryBatch.
??? It's what I said: "it's the OS or the CPU itself that decides the allocation [...] it's done in a very efficient way so you don't have to worry."I thought, based on link you gave me, core allocation is done on Android OS, developer can only tried to do multi thread for better performance. May be I was misunderstood
On a single core, that improves nothing, whatever OS you have. The main interest for an app on a single core is to be able to do something while an IO operation is pending, e.g. computing something while a data is fetched from the web or written to the disk.About performance, in windows OS, when CPU is multi core, multi thread improved performance a lot. In my case, it was at least 6-7 times faster.
You can already do it. Create 10 requests and send them. They will be handled by 10 background threads.What I have in mind, 20000 records, divided into 10 threads, each threads, handle 2000 records for download and insert operations, and if possible, do some analyzing downloaded data before inserted to local table.
What I have in mind, 20000 records, divided into 10 threads, each threads, handle 2000 records for download and insert operations, and if possible, do some analyzing downloaded data before inserted to local table.
You can already do it. Create 10 requests and send them. They will be handled by 10 background threads.
Sub GetData
DBRequestManager.ExecuteQuery(cmd1, 0, 1)
DBRequestManager.ExecuteQuery(cmd2, 0, 2)
DBRequestManager.ExecuteQuery(cmd3, 0, 3)
End sub
Sub JobDone(Job As HttpJob)
If Job.Success = true Then
If Job.JobName = "DBRequest" Then
Dim result As DBResult = DBRequestManager.HandleJob(Job)
If result.Tag = "1" Then
DoProc1
else If result.Tag = "2" Then
DoProc2
end if
end if
End if
End Sub
You did forget aSub JobDone(Job As HttpJob)
If Job.Success = true Then
If Job.JobName = "DBRequest" Then
Dim result As DBResult = DBRequestManager.HandleJob(Job)
If result.Tag = "1" Then
DoProc1
else If result.Tag = "2" Then
DoProc2
end if
end if
End if
End Sub
Job.Release
It depends the code you plan to run. Try it first without creating additional threads. It might be fast enough.This is only for download and update/insert operation, and for analyzing before update/insert data, still need threading library, right?
Haha, thanks for remind me. I did really forget about this code on my actual app.You did forget aat the end of the subB4X:Job.Release
Ok, I will try it.It depends the code you plan to run. Try it first without creating additional threads. It might be fast enough.
I think there is an Android app that seem to able to runs threads in their own core.You make a confusion between "multicore" and "multithreading". On all Android devices, many threads are run on the same core. That does not make things faster. That just gives the feeling that some things are run in parallel (but of course they're not). That won't change anything to your need. What you need is to run these threads in their own core for a true parallelism. In most cases, it's the OS or the CPU itself that decides the allocation. I don't know if you can force it on Android, but usually it's done in a very efficient way so you don't have to worry.
Unless you have a strong reason to think that the OS and the CPU do not do their job efficiently in allocating cores, I don't think you have to worry about that. In my ULV lib, I use concurrent threads to load images asynchronously and I do not force the allocation on different cores (I don't know how to do it in Java anyway) but it is obvious when running ULV on different devices that it benefits from multiple cores.I think there is an Android app that seem to able to runs threads in their own core.
The app is DroidFish+Stockfish engine, this is the chess program. It has a setting to let users to choose how many core to use for this app.
If users choose 3 cores, all these cores will run in max freq, other core will not. (Checked it via Trepn Profiler - only runs for Qualcom chipset)
As for app compile with B4A, it seem also runs in multicore, but not all core used at max freq. Only 1 core always run in max freq, even users do nothing / on idle. When users clicked or touch or do some task, others core get active, but not in max freq.
I don't what development tool to build DroidFish and maybe it is difficult to find tools (that has rapid development like B4A) that support multicore dev in Android.
My dev tool in Window OS also only support multithread.