About Question com.enthuware.ets.scjp.v6.2.496 :

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

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.496 :

Post by ETS User »

I didn't understand the concept of object wrapping.... infact the whole question and answer... can somebody explain me this?

canus27
Posts: 2
Joined: Thu Oct 24, 2013 7:57 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by canus27 »

A programmer is using the following class for wrapping objects and passing it around to multiple threads. Which of the given statements regarding this class are correct?

public class DataObectWrapper
{
private Object obj;

public DataObectWrapper(Object pObj){ obj = pObj; }

public Object getObject() { return obj; }
}
This question is what the above user (2 yrs ago) was referring to..an explanation would be nice:)

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

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by admin »

Hi Canus,
There is a detailed explanation already with the question. Could you please be a little more specific about which part you don't understand so that we can help?
-Paul.
If you like our products and services, please help us by posting your review here.

canus27
Posts: 2
Joined: Thu Oct 24, 2013 7:57 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by canus27 »

I understand how this works and the flow of the code. How is this wrapping an object? Looks to me (in my very limited experience) that this is a class declaration and constructor. Am I incorrect?

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

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by admin »

The class is not really doing anything other than getting and setting the internal object referred to by "obj". In that sense, it just wrapping the object referred to by obj. There is nothing much to it.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

cjgiron
Posts: 14
Joined: Fri Sep 09, 2022 5:03 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by cjgiron »

Hi Admin,

Just wanted to clarify my understanding of thread-safety in terms of objects. So if a class A has methods that modify instance or class variables of class A objects, that automatically means class A is not thread-safe? What if those methods that modify those variables are synchronized? Would the class then be considered thread-safe? I guess my current understanding is that synchronized methods make the object (either instance object for instance methods, or class object for static methods) thread-safe.

Thanks in advance!

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

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by admin »

Right, just because a method modifies instance or class variables of an object does not make that method or object thread- unsafe.

Yes, if a method is synchronized it means that that method is thread safe but that does not mean the object itself is also thread safe because there might be another unsynchronized method that modifies the instance fields. So, you have to look at the class in totality to determine whether it is thread safe or not.
If you like our products and services, please help us by posting your review here.

cjgiron
Posts: 14
Joined: Fri Sep 09, 2022 5:03 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by cjgiron »

Hi Admin,


The double negatives in this line of your answer are a little confusing:
just because a method modifies instance or class variables of an object does not make that method or object thread- unsafe.
Are you saying that, even if a class contains a method that modifies instance or class variables, the method or object of that class could be still be thread-safe?

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

Re: About Question com.enthuware.ets.scjp.v6.2.496 :

Post by admin »

That is correct.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 52 guests