multithreading - How to implement Java single Database thread -


I have created a Java program that connects to a SQLite database using SQLite4Java.

I've read the serial port and the value to the database. It worked fine in the beginning, but now it has increased my program and multiple threads to me I tried to handle it with SQLiteQueue-variable, which performs database operations with something like this:

  is public void insert Krenplemp value (final SQLiteStatement Stmt last long periods of time, the final double tempValue) {if (checkQueue ( "insertTempValue (SQLiteStatement, long, double)", "queue not running ! ", False)) {queue.execute (New SQLiteJob & lt; Object & gt; ; () {Object secures object (SQLiteConnection connection) throws SQLiteException {stmt.bind 1, log time); Stmt.bind (2, tempValue); Stmt.step (); Stmt.reset (true); Return tap;}}); <}>      

But now can not reporting my Skyueliti-Class statement:

  DB [ 1] [u]: Settlement [INSERT (?,?)] DB [1] [U] SQLiteDB $ 6 @ FBFD from foreign thread: job exception com. Functioning SQL 4 Java SQLite expansion: [-92] Statement of Settlement   

is not executed.

I have tried to understand what is wrong and I think that I need a Java wrapper, which is a thread that is known to all threads of database operations through other threads.

This is my problem. I do not know how to implement it in a good way. How can I make a method call and can ensure that it always walks through a single thread?

A run () method to use your database code in a package and make all sections package private Write a Runnable or Thread sub-class that runs a loop with To perform a loop check for queued information requests, and run the appropriate database access code to find the information, mark the complete request before entering the information in the request and returning to the queue.

The client code queue is waiting for the data request and response, perhaps by blocking the request until the request is fully marked.

data request will look something like this:

  public class // client thread InsertTempValueRequest {// client threads before queue This method is called to build the object after the public puts in line InsertTempValueRequest (last long periods of time, the final double tempValue) {this.logTime = logTime this.tempValue = tempValue} // this is called the client thread after the queue to check method of full public Complete () {return is complete; } // this method while the object is executed (SQLiteConnection connection, SQLiteStatement statement) is added to the database thread after dequeuing using {// execute logTime and tempValue member data, and commitComplete = true; } Private volcano long time; Private volatile double tempValue; Private volatile boolean is absolute = false; }   

This will work, but I suspect that there will be many problems in implementation. I think you can also get it using a lock, which allows only one thread to access the database, and also - this is different from your current situation - the beginning of access by creating database resources - Including statements - from scratch, and disposing of those resources before issuing lock.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -