Callable, ExecutorService and Future are not classes.You want to execute a task that returns a result without blocking. Which of the following classes from java.util.concurrent package will be required to achieve this?
About Question enthuware.ocpjp.v7.2.1235 :
Moderator: admin
-
- Posts: 19
- Joined: Thu Feb 28, 2013 9:47 am
- Contact:
About Question enthuware.ocpjp.v7.2.1235 :
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
While it is true that these are interfaces, it is common practice to call both (interface and class) as class when the difference is irrelevant or is not to be "revealed" for the point in discussion. After all, there is a "class" file with extension .class, not .interface
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 20
- Joined: Fri Jun 19, 2015 9:17 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
The common word correctly addressing both classes and interfaces is type. BTW, it may be also used for enums and primitive types, if you want to include them into a question
-
- Posts: 21
- Joined: Thu Jul 16, 2015 4:22 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
That's ridiculous. Some questions you will get wrong if you use this interpretation that an interface is a class. Is the exam still giving such incorrect questions?Alexey Berezkin wrote:The common word correctly addressing both classes and interfaces is type. BTW, it may be also used for enums and primitive types, if you want to include them into a question
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
We have seen candidates getting questions that are somewhat vague or ambiguous. That is why we have included such questions. It is very easy for us to remove or alter such questions than to be at the receiving end of anger from our customers but then we will not be able to make the reader aware of such issues that they may face in the exam.
So our suggestion is to not read too much into the statement and rely on common sense.
HTH,
Paul.
So our suggestion is to not read too much into the statement and rely on common sense.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
Common sense won't help. Here "classes" is supposed to include interfaces, in other questions, it is supposed to exclude them.
I don't know whether that inconsistency is in the exam. Is there a possibility that people report inaccurate information from their exam experience?
I don't know whether that inconsistency is in the exam. Is there a possibility that people report inaccurate information from their exam experience?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
It is possible that some information received from test takers is inaccurate. But at the same time, it is also true that there are such inaccuracies in the exam.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
Please excuse me for the this question that might sound trivial for some of you,
but the way the question is asked :
I suppose it does not mean simply waiting for a task to end until we start the second one...???
but the way the question is asked :
So by saying without blocking what do they actually mean?You want to execute a task that returns a result without blocking.........
I suppose it does not mean simply waiting for a task to end until we start the second one...???
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
"Blocking" means "stopping execution to wait for some other process to produce some kind of a result". Often I/O, in a multithreading context it would be waiting for another thread to e.g. terminate, or deliver some data.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
Thanks tooforger, so I realize that my assumption was not so far from truth,
BTW where did you get the definition of the term blocking ? since i went through the ks&&bb guide
chapter on concurrency and didn't find it there....
BTW where did you get the definition of the term blocking ? since i went through the ks&&bb guide
chapter on concurrency and didn't find it there....
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
It's a general IT term. I first read it in descriptons of Unix system calls.
-
- Posts: 8
- Joined: Wed Mar 16, 2016 10:57 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
Hi,
So I'm a bit confused about something.
I have always understood that runnables don't return anything while callables do but then I went into the API documentation for ExecutorService today and saw this:
<T> Future<T> submit(Runnable task,
T result)
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
Parameters:
task - the task to submit
result - the result to return
Returns:
a Future representing pending completion of the task
Throws:
RejectedExecutionException - if the task cannot be scheduled for execution
NullPointerException - if the task is null
If runnables never return anything then why is this method in the API?
Thanks
So I'm a bit confused about something.
I have always understood that runnables don't return anything while callables do but then I went into the API documentation for ExecutorService today and saw this:
<T> Future<T> submit(Runnable task,
T result)
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
Parameters:
task - the task to submit
result - the result to return
Returns:
a Future representing pending completion of the task
Throws:
RejectedExecutionException - if the task cannot be scheduled for execution
NullPointerException - if the task is null
If runnables never return anything then why is this method in the API?
Thanks
-
- Posts: 38
- Joined: Fri Nov 13, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
result is passed in to submit() and returned in the Future when the Runnable is finished.
That's useful if the Runnable modifies result.
It is also useful if you need to pass a Future into some API, already have the result ready but don't want to have it processed before the Runnable is finished.
That's useful if the Runnable modifies result.
It is also useful if you need to pass a Future into some API, already have the result ready but don't want to have it processed before the Runnable is finished.
-
- Posts: 14
- Joined: Mon Jun 20, 2016 11:16 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
I read in K&B book,
Callable<Integer> c= new Callable();
Future<Integer> f= ex.submit(c);
try{
Integer v=f.get(); //blocks until done
System.out.println(..);
}
catch(InterruptedException| ExecutionException ex){
System.out.println(..)
}
It says:
Interrupted Exception:Raised when the thread calling the Future's get() method is interrupted before the result can be returned.
Now my question is should the get() method always placed inside the try/catch or throws exception mentioned.Am I correct?
Callable<Integer> c= new Callable();
Future<Integer> f= ex.submit(c);
try{
Integer v=f.get(); //blocks until done
System.out.println(..);
}
catch(InterruptedException| ExecutionException ex){
System.out.println(..)
}
It says:
Interrupted Exception:Raised when the thread calling the Future's get() method is interrupted before the result can be returned.
Now my question is should the get() method always placed inside the try/catch or throws exception mentioned.Am I correct?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
Well, InterruptedException is a checked exception so you have to either put the call to get in a try catch or declare the exception in throws clause the method. This is same as for any other checked exception.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 97
- Joined: Wed Dec 28, 2016 9:00 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1235 :
I have huge respect for this! I hope all the hard work of you guys as well as me preparing for this monster test pays off!admin wrote:We have seen candidates getting questions that are somewhat vague or ambiguous. That is why we have included such questions. It is very easy for us to remove or alter such questions than to be at the receiving end of anger from our customers but then we will not be able to make the reader aware of such issues that they may face in the exam.
So our suggestion is to not read too much into the statement and rely on common sense.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 139 guests