aspose file tools*
The moose likes JDBC and the fly likes Dirty read is experienced for the same thread???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Dirty read is experienced for the same thread????" Watch "Dirty read is experienced for the same thread????" New topic
Author

Dirty read is experienced for the same thread????

Senthil Kumar Sekar
Ranch Hand

Joined: Aug 08, 2010
Posts: 45

Hi,
Can anyone tell me if Dirty read is experienced by the same thread only?

Because,

I have two classes and one table(Employee - 3 rows)

Class 1
1) set autocommit - false
2) selecting the emp table - prints 3 rows
3) inserting one new row
4) selecting the emp table - prints 4 rows -> Dirty Read Occurs here

Class 2
1) select the same table - It prints only 3 rows ->Does not include the new row.

So,Does that mean Dirty Read is experienced by the SAME THREAD ONLY

Thanks.

Regards
Senthil Kumar Sekar
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

1. Are these two classes, threads?
2. What type of Statement have you used?
3. What isolation levels have you set for your Statement objects?

S.D. MADHAN
Not many get the right opportunity !
Senthil Kumar Sekar
Ranch Hand

Joined: Aug 08, 2010
Posts: 45

1) those are two separate classes.So executing them means a separate thread.
2) Normal Statement
3) Isolation level - TRANSACTION_REPEATABLE_READ

Thanks.

Regards
Senthil Kumar Sekar
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

In what manner are the two classes executed? (sequential/parallel/wait-notify/....etc...)
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
Hi Senthil,

I don't think your class 1 is experiencing any dirty reads. Its the regular behavior. You establish a DB session the moment you open a connection. Within the session all uncommitted changes are readable. Since you have autoCommit = false, the moment you close your connection the insert would be rolled back and any further select from class1 will/should show only 3 records on the emp table.

Your class 2 sees only 3 records since class 1 has not committed the records yet. Thus the class2 (which has a separate DB session) is not experiencing the dirty read.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


1) those are two separate classes.So executing them means a separate thread.

Not sure what you mean by "2 classes" == "2 threads" (especially given the subject of this post). Can you explain how you instantiates these?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dirty read is experienced for the same thread????
 
Similar Threads
copying arrarys into a different class with methods
SQL question
adding JCheckBox in JTable
adding a JCheckBox in a JTable
Foreign key problem