How to ask OS to create threads? With threading library?You can ask the OS to create threads for you. You don't have any control over the cores. The OS is responsible for that.
I am still new in sqlite features, and when using multi threads, I divided data into available threads, for example, there are 100 records & 4 threads, I assigned each threads with 25 records.Note that tou need to be careful with SQLite database and multithreaded apps.
Have you encountered any performance issue?
Do you really need to retrieve 20000 records each time? Or just the first time? What's the volume of data? And what's the accepted duration to write these records to the dabase? Because, enclosed in a transaction, that should be done in less than 30 seconds.100 records is just for an example. Actual records started with about 20000 records and growing.
I can post a codes latter when on my CPU, right now, browsing via tablet.
Do you really need to retrieve 20000 records each time? Or just the first time? What's the volume of data? And what's the accepted duration to write these records to the dabase? Because, enclosed in a transaction, that should be done in less than 30 seconds.
Can you post the code?
Atleast it seems your downloads are not being threaded for some reason. Without seeing code it is impossible to say, also I am not familiar with RDC.
However, since all HttpUtils2 will be raising the same JobDone back on to the main thread, you need to ensure that JobDone delegates the tasks off the Main thread, and the main thread remains empty.
Sub GetData
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data1"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data1")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data2"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data2")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data3"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data3")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data4"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data4")
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success = true Then
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqM.HandleJob(Job)
If result.Tag = "get_data1" OR & _
result.Tag = "get_data2" OR & _
result.Tag = "get_data3" OR & _
result.Tag = "get_data4" Then
Log(DateTime.Time(DateTime.now))
UpdateData(result)
End If
End If
Job.Release
End Sub
Sub UpdateData(result As DBResult)
Try
Private ValC1,ValC2,ValC3,ValC4 As String
Private ValI1,Val2,Val3 As Int
For Each records() As Object In result.Rows
ValI1 = records(6)
ValI2 = records(0)
ValC1 = records(1)
ValC2 = records(2)
ValC3 = records(3)
ValC4 = records(4)
ValI3 = records(5)
SQL.AddNonQueryToBatch("insert into table(Field1,
Field2,Field3,Field4,Field5,Field6,Field7) values(?,?,?,?,?,?,?)",Array As Object(ValI1,ValI2,ValC1,ValC2,ValC3,ValC4,ValI3))
Next
SQL.ExecNonQueryBatch("InsData")
Catch
Log(LastException)
End Try
End Sub
Sub InsData_NonQueryComplete(Success As Boolean)
Log(DateTime.Time(DateTime.now))
End Sub
You were right, downloads is was not threaded, in runs in sequence.
and httpjobs runs parallel and in fact your codeUnder the hood DBRequestManager creates a HttpJob for each request. The job name is always "DBRequest".
Sub GetData
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data1"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data1")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data2"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data2")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data3"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data3")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "get_data4"
DBRequestManager.ExecuteQuery(cmd, 0, "get_data4")
End Sub
I dont know what the requestmanager does. Maybe he take care of the order. But maybe it is just accidental that the order is correct.From the log, each seem that every job executed after previous job finished.
You misunderstood, may be my lack of english made me not explain clearly, sorry.I dont know what the requestmanager does. Maybe he take care of the order. But maybe it is just accidental that the order is correct.
I DONT know and not worked with dbrequestmanager before. But if it just fires 4 httpjobs like i would expect (after read the sidenotes about httpjob in the docu) then the order is not garanteed.
Maybe we need @Erel ´s wisdom to answer this
Alternative 2 is complex cause must keep a log on server about new data, inserted data & deleted data and then record every device id and keep tracks which device id has updated its data and which one has not. Also must consider device that is not updated its data, but server already update/delete the data. If running well, device could be more than 250.
Volume of data, for first time is about 20000 rows x 8 columns. Column data type, 3 int, 1 char(3), 2 varchar(60) & 1 varchar(4).
This database server is also used in LAN and I am pretty sure that it is set for asynchronously, but I will check again its JDBC.Maybe the database server handles the requests synchronously.
You can see performance numbers of a server app created with B4J and MySQL: http://www.b4x.com/android/forum/threads/37502/#content
It is similar to RDC.
If you haven't changed it then it creates a pool of 15 connections.Is there any settings in I should also check in file c3p0.properties
1,4 Mb for the whole database is not too heavy to consider a complete download each time, but if your user has a very slow connection or a limited volume of data per month, he/she won't be happy to have to download everything each time he/she uses your app.
In your scenario (multiple readers for a remote database), the option 2 is the way to go and is not as complex as you think:
1) Add a timestamp to each record and query from the client only the records that are newer than the latest timestamp retrieved with the last download.
2) Create a new table on the server storing the ID of all deleted records with the timestamp of their deletion (this table could be filled automatically with a trigger). Do the same kind of query as above to know the records to delete.
But how do you get only the updated records? I don't understand. Your solution seems only valid for a complete table to download.I will modified this idea a bit :
1) create new table on server & client, consist only 1 field,type incremental int id
2) every time records on server get update/insert/delete, id on server's table increased by 1
3) when users login to app, app query for id on server, compared it with id on client, if id on server is bigger, means data on server has changed, then app will query server for these data, download it, then update id on client with id on server
4) not using timestamp on every records, but using auto increment int, cause there are three local timezone in my country. If using timestamp, I will get another headache to make sure same timezone of every client with timezone on server.