should I use synchronized to control threads to have access to database?
i know i can lock the table in databse when thread A is writing data into
that table, so i can protect the table from be modified by other threads.
But in this condition,other threads can only be stopped when they try to
write data into the table.And what i want to do is to prevent them at the
beginning! If other threads must spend much time to work out the data that
will be stored into the table,stop them when they try to work out the data
isn't better? And i want to use synchronized to deal with it: class XX(){
public synchronized writeDataToTable(.....){
.........//some code to work the data that will be stored into the
table.And assum this process(work out the data) will cost much
time
DBhelper.save(data)// store the data into the table
} Am i thinking right?
No comments:
Post a Comment