Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to simulate multi-thread to test Data ?

 
ZhiYuan Lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
how to simulate multi-thread to test Data ? now i just have:
for (int i = 0; i < 100; i++)
new testThread().start();

//in testTeread
public void run() {
//do something such delete, add, find... Random
}
but how to do purposeful test?and how to test if my Data is thread safety and lock/unlock is working right?

thanks
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is one test. Start 20 threads, each trying to decrement a particular field of the same database record 200 times, in a loop. If at the end of the run the field value is reduced by exactly 4000, you pass.
 
Svetlana Koshkina
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is my test (you have to modify some lines:
how you get your data and other stuff). It's very unfriendly to read and hostile to run(if your app. is at early stage, your file most likely will be corrupted at the end) just to give you an idea. You can mold it into anything you want.
It is earliest test that tests just implementation of data. Later I had for all kind of clients too.
 
ZhiYuan Lin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
hi Svetlana your code is help me much,thank you again
but it is random multi-thread test, i still want to know some approach to test purposeful , is it exist that can testify my Data
is safety?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic