I have two methods method A and method B. Method A is responsbile for sending bills to user and Method B is responsbile for updating database. Method B uses PreparedStatement. Method A is run by different concurrent threads at a time. For example
Thread 1- Method A
Thread 2- Method A
Thread 3- Method A
Method A calls Method B to update database for fail or success of the billing.it's like
void A()
{
send billing sms
if (successful)
{
//update database with successful status
status='success'
}
if unsuccessful{
status='unsuccess'
}
method B(status, connection);
}
void B(Status s, Connection con)
{
PreparedStatement codes.. for update
}
Since, Method A is called by different concurrent threads at a time, How can I implement PreparedStatement Batch function in method B saying I want to update 50 transactions at once and not one by one. I want some counter either created on method A (but since concurrent threads run this method at once, is this possible?) or in method B (but counter variable will again be 0 when called by different concurrent threads, so is this possible?) OR making a Global Counter Class such that each time method B () is called this counter is increased and once it reaches 50 then batch update executes (No idea of it)..
Please advise!!