About Question enthuware.ocpjp.v7.2.1335 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by jagoneye »

Thanks though I don't want to get into the details of Class since it is used more in reflection and since reflection is not listed in the syllabus I'd rather look into it after the exam.

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by horst1a »

I am very puzzled about this question. Are there not two threads each having his own object 'TestClass', so they dont share the instance variables ? Is that right and it is the static declarer of i1,i2.. that makes the threads share these ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by admin »

Yes, there are two threads created using two TestClass objects. But there are no instance fields in the given code!! Also, instance fields are not shared between instances. Each instance gets its own copy of instance fields
Yes, i1, i2, j1, j2, k1, k2 are all static and are shared by the two TestClass isntances.
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by crazymind »

I try to figure out the behaviour of synchronized(lock1) and synchronized(lock2). Does synchronized on a static monitor will block thread using different object instance and thread using same object instance?
he only way a letter could be printed would be if the method workWithoutLocks() was executed between the time the first and the second variable was incremented.
Do you mean thread1 increment the first variable and thread2 execute condition of if statement?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by admin »

>Does synchronized on a static monitor will block thread using different object instance and thread using same object instance?
Sorry, I am not able to understand what you mean by this.
>Do you mean thread1 increment the first variable and thread2 execute condition of if statement?
Yes.
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by crazymind »

admin wrote:
Tue Mar 12, 2019 10:10 pm
>Does synchronized on a static monitor will block thread using different object instance and thread using same object instance?
Sorry, I am not able to understand what you mean by this.
>Do you mean thread1 increment the first variable and thread2 execute condition of if statement?
Yes.
By that I mean, lock1 is a static field; therefore, it is shared among the instance of TestClass.
If Thread1 and Thread2 are created by same object, Thread1 acquire the lock and access the synchronized block. Thread2 can not access.
If Thread1 and Thread2 are created by different object, Thread1 acquire the lock and access the synchronized block. Thread2 can not access since static lock share among the instances.

So there is no way to access the synchronize block (use static object as a lock) unless the lock is released?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by admin »

There are two synchronized blocks and they are using two different locks - lock1 and lock2.
If you like our products and services, please help us by posting your review here.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1335 :

Post by crazymind »

admin wrote:
Tue Mar 12, 2019 10:47 pm
There are two synchronized blocks and they are using two different locks - lock1 and lock2.
Yeah, Sorry, I mean conceptually, if I have a synchronized block use a static lock.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 32 guests