Results 1 to 4 of 4
- 10-06-2008, 12:20 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 31
- Rep Power
- 0
[SOLVED] Can two threads call two different synchronized instance methods of an Objec
Can two threads call two different synchronized instance methods of an Object?
I am still not sure on this, If I have two different methods in a object and two different threads are calling them.....is it possible?
Not sure if I understood the question right.... but looks like really fundamental question. Please provide your suggestions and pointers...Live life king size
[Lucene]
- 10-06-2008, 12:22 AM #2
Member
- Join Date
- Oct 2008
- Location
- US
- Posts
- 58
- Rep Power
- 0
No. If a object has synchronized instance methods then the Object itself is used a lock object for controlling the synchronization. Therefore all other instance methods need to wait until previous method call is completed.
See Sample Code which demonstrate it very clearly.
____________________________________________
Software Wiki | Interview FAQs | Lucene Search | Oracle | ORM | Struts2 | Job SeekerHave fun....
JAVA FAQs
- 10-06-2008, 12:25 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
Try out some code yourself, it should be more easier. Also it will be memorized. You can try more combination on same multi threaded applications.
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | DalCheers,
Eat Healthy Stay Fit
- 10-06-2008, 12:27 AM #4
Member
- Join Date
- Oct 2008
- Posts
- 68
- Rep Power
- 0
Btw just to answer your question,
You cannot call two synchronized methods of a class on the same object. This is the use of synchronization. If you can call two synchronized methods on the same object then there is a chance of corruption of the state of the object. Synchronization helps you to avoid this....
____________________________________________
Priya,
Cooking is Fun | Eat Healthy Stay Fit | Sweets | Raita | Bread | DalCheers,
Eat Healthy Stay Fit
Similar Threads
-
accessing instance variables from static methods
By ravian in forum New To JavaReplies: 7Last Post: 03-01-2009, 10:09 PM -
How to call methods of different classes
By adeeb in forum New To JavaReplies: 2Last Post: 06-06-2008, 06:08 AM -
How to synchronize threads on an object
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:39 PM -
How can I call java class methods in Oracle 10g PL/SQL
By searcher34 in forum JDBCReplies: 0Last Post: 01-02-2008, 01:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks