File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Multi-threading issues while handling JDBC transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Multi-threading issues while handling JDBC transactions" Watch "Multi-threading issues while handling JDBC transactions" New topic

Multi-threading issues while handling JDBC transactions

Elamurugu Lakuvan

Joined: May 02, 2003
Posts: 1
I have 5 threads running, each thread tries to insert some records into the database. Each thread is unaware of what the other thread is processing. In this scenario when one of the thread out of 5 is facing some problem while inserting into database, it tries to rollback its own transaction. Is it possible to rollback the transactions of the other threads and also can we stop the execution of other threads??
Code snippets:
public class ThreadSample {
//Our own implementation
private TransactionContext getTransactionContext(Context context) {
return TransactionContext(context.getTransactionContextId());
class MyThread extends Thread {
public void run() {
try {
TransactionContext txt = getTransactionContext(context)
Connection con = txt.getConnection();
<<insert records into table>>
txt = null;
} catch (Exception ex) {
} finally {
if (txt != null) {
public static void main(String[] args) {
MyThread t1 = new MyThread();
MyThread t5 = new MyThread();
Jane Somerfield
Ranch Hand

Joined: Jul 20, 2002
Posts: 193
The five transactions are independent from
each other. Rollback on one does not affect
others.If DB implements SERIALIZABLE, there
should be not a problem in your case.
I agree. Here's the link:
subject: Multi-threading issues while handling JDBC transactions
jQuery in Action, 3rd edition