I am using Sqlite3 Database in my project. For testing purpose, I need to keep database busy for a long time . How to achieve that ? Is there a command or script I can write a keep database busy.
Can somebody please help ?
The database is busy when there is some active transaction.
To force some transaction, just execute BEGIN EXCLUSIVE . This could be done from your program, or simply by hand from the sqlite3
command-line shell:
$ sqlite3 /some/where/mydatabase.db
SQLite version 3.8.5 2014-06-04 14:06:34
Enter ".help" for usage hints.
sqlite> BEGIN EXCLUSIVE;
sqlite> -- the DB is now locked ...
sqlite> COMMIT;
Given that this is for testing purposes , one way is to have a thread do constant inserts into the database. Then you would use another thread to do the reading. I can see it being done in the following way (using pseudocode) in junit:
@Before
public void setup(){
//start thread for inserting
}
@After
public void destroy(){
//stop thread for inserting
}
@Test
public void testRead(){
//do the test for reading
}
The above would keep the database busy for the duration of each test. You could have a seperate application that inserts for a defined time limit. This would be done in this way:
public static void main(String [] args){
//mark startTime
//while currentTime - startTime < timeLimit (in milliseconds)
//insert into db
}
The part of the question I do not understand is:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.