Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Please clarify my doubt

Have Programming Question? Ask it here!
 
 
 


karthik
Please clarify my doubt
0 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners


/here is my sample code for deadlock/

class A { synchronized void foo(B b) { String name = Thread.currentThread().getName(); System.out.println(name + "entered A.foo()"); /*try { //Thread.sleep(1000); } catch(InterruptedException e) { System.out.println("A Interrupted"); }*/ System.out.println("Trying to call B.last()"); b.last(); } synchronized void last() { System.out.println("Inside A.last()"); } } class B { synchronized void bar(A a) { String name = Thread.currentThread().getName(); System.out.println(name + "entered B.bar()"); /*try { Thread.sleep(1000); } catch(InterruptedException e) { System.out.println("B Interrupted"); }*/ System.out.println("Trying to call A.last()"); a.last(); } synchronized void last() { System.out.println("Inside B.last()"); }

} class Deadlock implements Runnable { A a = new A(); B b = new B(); Deadlock() { Thread.currentThread().setName("Main Thread"); Thread t = new Thread(this,"Racing Thread"); t.start(); a.foo(b); System.out.println("Back in Main Thread"); } public void run() { b.bar(a); System.out.println("Back in other thread"); } public static void main(String[] args) { new Deadlock(); }

} My question is that class A has 2 synchronized methods.Object a of class A is calling a.last method .Why it is not entering into last method ??? If class has 2 synchronized methods as in the example if same object of the class calls both the methods will it give access to both of those methods???


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Please clarify my doubt
Please clarify my doubt  /here is my sample code for deadlock/ class A { synchronized void foo(B b) { String name...[] args) { new Deadlock(); } } My question is that class A has 2
Clarify my doubt - JSP-Servlet
Clarify my doubt  Hi All, Although i know the concept of Servlet & JSP, but I have never got a chance to work in EJB . So could u please tell me how to create web Project in netbeans and deploy it in tomcat AND/OR creating a web
Advertisements
please clarify regarding capacity method of my below string buffer class example
please clarify regarding capacity method of my below string buffer class example  hi here is the program below: > import java.lang.*; public... vinodaRajDeepakMohit vinodaRajDeepakMohitraju length is24 capacity is30 my question
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back. Yes. I want a page to use id of parents to do the search for the match. So... the matching tutors to the parent. I was telling you that my degree
Clarify my last question's answer - Java Beginners
Clarify my last question's answer  Dear expert, I've tried out... expert's advise. Many thanks.   Hi Friend, Please clarify your... did not specify my question too clearly. Here's my 2 database
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
PLEASE HELP WITH MY JAVA
PLEASE HELP WITH MY JAVA  Hey my name is Gavin and im a student at school that takes IT. my teacher has gave me a problem and i can't figure it out please help!!!!!!!! it is a for-loop question: Display the first 5 multiples
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser... the name on that button.can u please help me out to solve this problem.if u need.... FAYAZ.  Hi friend, Please specify your requirements in detail
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok button. 6 Textbox to Add the 6 Team Name. Each Team Name In String(Like- A,B,C,D,E,F) When I Add This Six Team Name In Six Text Box Then I Will Click On Ok Button
please help.. this my importtant project..!!!!!
please help.. this my importtant project..!!!!!  Consider the Algebra: Solving quadratic equations. The two roots of a quadratic equation ax2 + bx + c = 0 can be obtained using the formula: ???????????1= ?????+?????2
My big doubt on java prgmn.. need solution asap
My big doubt on java prgmn.. need solution asap  How do you write prgrm 4 dis : 3% discount is given if payment is made within 30days of purchase. date of purchase and payment entered by user
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
doubt this
doubt this  what is the use of "this" and "super" keyword
plz try to clear my doubt for shuffling multi-dimensional array
plz try to clear my doubt for shuffling multi-dimensional array  hi, if v r using Arrays.asList() means, it may shuffle the row wise list only... v want to shuffle the ful entire multi-simensional array means wat v want to do
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
My screen EPAD is broken ...please help
My screen EPAD is broken ...please help   iam in iraq and my screen EPAD is broken ,.please help..can tel me a place to join it to solve this problem ?..Sory
Help me please with my final homework
Help me please with my final homework  Write a Java program of your choice that demonstrates the following concepts: ? Input and Output. ? Selection/Conditional (e.g. if statement). ? Arithmetic. ? Loops. ? Arrays
Syntax error in my UPDATE..please advise
Syntax error in my UPDATE..please advise  Hi experts, I tested my...; stmt.executeUpdate(sql); Please advise how should I change my SQL to use Heidi MySQL...) And here's my UPDATE Statement: String sql = "UPDATE members SET strNRICNO
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades function computeGrade( ) { var hw, lab, midt, fin, avg; hw = parseFloat
doubt
doubt  can you please explain the following code System.out.print((k >=10) ?+ k : " " + k
clarify date class - Java Beginners
clarify date class  Dear, clarify this question... "Develop Date class in Java similar to the one available in java.util package. Use JavaDoc... in java.util or any packages.. please. thanks in advance. regards S.v.Doss
please do respond to my problem sooooon sir - Java Beginners
please do respond to my problem sooooon sir  Hello sir, Sir i have... on the link in my browser the link is opened in the internet explorer.i need to open the link also in my own browser.Hope you will help me out.And also sir i need
this is my javascript code and i am not understanding the mistake in this,please help me?
this is my javascript code and i am not understanding the mistake in this,please help me?  <html> <h2>Form Validation</h2>...; if((nn1.value==null)||(nn1.value=="")){ alert("Please Enter
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert...) ... but this is not giving me the exact result as the above PHP code is giving. So please...;   Thank you , But this not my exact solution for my problem. What
Please help me to modify my java code from php code
the exact result as the above PHP code is giving. So please help me to convert
this is my file upload page, here i am not getting tags input field value to my servlet,please suggest a solution?
this is my file upload page, here i am not getting tags input field value to my servlet,please suggest a solution?  <html> <head> <script type="text/javascript"> var counter =1; function
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how... our own plugin????? and please help me. how to use dao s while integrating struts with hibernate..??? actually what is the purpose of dao's ????? please help
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how... our own plugin????? and please help me. how to use dao s while integrating struts with hibernate..??? actually what is the purpose of dao's ????? please help
Please tel me .In my System Oracle9i and J2sdk1.6 are Installed.Why this problem occures and what is the solution?
Please tel me .In my System Oracle9i and J2sdk1.6 are Installed.Why this problem occures and what is the solution?  Exception in thread "main" java.lang.UnsupportedClassVersionError: select (Unsupporte d major.minor version 50.0
doubt in struts - Struts
doubt in struts   i don't understand the concept on Resource bundle in struts can u please help me out
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page  <p>?xml version='1.0' encoding...; Please visit the following link: JSF Example
doubt on synchronized block in java
. I think you got my doubt. I request you to clarify my doubt based on below...doubt on synchronized block in java  Hi ! some people are feeling bore on my regular questions on threads. Do not feel bore on my regular questions.I
clarify bt/w service() and doget/dopost()
clarify bt/w service() and doget/dopost()   Dear friends, i ve question regarding service()and doget/dopost.. the container calls service() where it does the service for the request so then wat is the role of doget/dopost plz
Doubt Regarding Charts
Doubt Regarding Charts  Hi, Can you please help me out by answering "hoe to include charts in core java code and struts code" thanks in advance, Swaroop Eswara   Please visit the following link: Jfreechart
big doubt
(); } %> </body> </html> please correct it if any
servlet doubt on online examination system
the programs using java servlet. MY PROBLEM and doubt is 1. how 2 skip...servlet doubt on online examination system  hai. sir ,i am doing... plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..its urgent   Please go
Doubt about Xstream Converter
Doubt about Xstream Converter  Hi, I am using the Xstream freamwork... to read some properties of my Xml file, but when I changed my application to process xml files using Multithreading, I saw my application consume all avaliable
Doubt in struts - Struts
Doubt in struts  I am new to Struts, Can anybody say how to retrieve... know how to do. Please help me in this regard. It will be helpful, if explained with code?  Hi friend, Please visit the link to solve the problem
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
 

 

 

DMCA.com