Unchecked exceptions

From a book:
"When a class undergoes revision, it is not a violation of source or binary compatibility if an exported method is modified to throw additional unchecked exceptions.
Suppose a class invokes a method from another, independently written class. The authors of the former class may carefully document all of the unchecked exceptions that each method throws, but if the latter class is revised to throw additional unchecked exceptions, it is quite likely that the former class (which has not undergone revision) will propagate the new unchecked exceptions even though it does not declare them."
What does the last line about propagating mean? It sounded pretty simple up until then...what I got was that your code can call other code that can add unchecked exceptions at any time...correct? I just don't understand the ending.
Thanks.

But I thought one main differentiating factor of
unchecked exceptions is (more often than not -- if
not always) that you cannot recover from them.You generally either can't or shouldn't, because they're a sign of a programming error or of seros system trouble.
I'd think it'd be an irrelevant point that a callee
could add new unchecked exceptions because (forget
the new unchecked exceptions)It's worth making it clear that unchecked exceptions are not part of the method's contract.
what's a coder to do
with unchecked exceptions the callee already HAS
documented!?Usually nothing. Often it's just worth documenting them as a way laying out preconditions, assumptions, and limitations of the method being called.

Similar Messages

  • Checked and unchecked exceptions - when to use which ?

    Hi,
    Example:
    public void go(String[] args) {
       if(args.length==0)
          throw new //   <= what type of an exception should come here ?
    }Is there a good explanation when to use which one ? I know that generally
    unchecked exception are the exceptions associated with errors in the logic
    of your applications and checked are those which you can not determine
    (like files, networks problems ....).
    Thanks,
    Adrian

    There is no, "I think it is better to us a type-XXX exception here because of conditions 1, 2, and 3" scenario.
    Checked exceptions are of type java.lang.Exception and must be handled in one of two ways- try/catch constructs or having the method state it throws the checked exception.
    Unchecked exceptions are of type java.lang.Error or java.lang.RuntimeException. If the problem is an Error, something very bad has occurred like running out of memory. If it is a RuntimeError, then it probably came from a program bug. In both cases, there is no way for you to know when they will arise. Therefore the compiler does not force you to handle these unusual circumstances.
    If you think of piece of code may throw an error like an I/O operation, and you do not have code to handle that possibility, the compiler will let you know. After you have been programming long enough, you'll begin to know when you need try/catch constructs without Mr. Compiler yelling at you. ;-)
    Edited by: filestream on Sep 14, 2007 5:37 PM

  • Servlet losing connection to bean after a one Unchecked exception.

    i get this exception continuously :
    20010827175301793 ERROR 27 Aug 2001 17:53:01,793 CMServlet :
    java.rmi.NoSuchObjectException: <mapped>
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.io.IOException.<init>(Compiled Code)
    at java.rmi.RemoteException.<init>(RemoteException.java:56)
    at java.rmi.NoSuchObjectException.<init>(NoSuchObjectException.java:50)
    at com.kivasoft.eb.EBExceptionUtility.idToSystem(Unknown Source)
    at com.kivasoft.ebfp.FPUtility.replyToException(Unknown Source)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_kcp_stub_WapCMEntrance.exec
    ute(ejb_kcp_stub_WapCMEntrance.java:356)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_stub_WapCMEntrance.execute(
    ejb_stub_WapCMEntrance.java:71)
    at com.valis.cellmate.servlets.CMServlet.executeCmd(CMServlet.java)
    at
    com.valis.cellmate.servlets.LoginHandler.updateServerOnUserLogin(LoginHandle
    r.java)
    at
    com.valis.cellmate.servlets.BackdoorLogger.doGetOrPost(BackdoorLogger.java)
    at com.valis.cellmate.servlets.CMServlet.service(Compiled Code)
    at javax.servlet.http.HttpServlet.service(Compiled Code)
    at com.netscape.server.servlet.servletrunner.ServletInfo.service(Compiled
    Code)
    at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Compiled
    Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Compiled Code)
    at java.lang.Thread.run(Compiled Code)
    After i get once an unchecked exception :
    20010827175231868 ERROR 27 Aug 2001 17:52:31,869 CMServlet :
    com.netscape.server.eb.UncheckedException: unchecked exception thrown by
    impl [email protected]513cb;
    nested exception is:
    java.lang.NullPointerException
    java.lang.NullPointerException
    at
    com.valis.cellmate.wap.statelessSessionBeans.WapCMEntranceBean.execute(WapCM
    EntranceBean.java)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_skel_com_valis_cellmate_wap
    statelessSessionBeansWapCMEntranceBean.execute(ejb_skel_com_valis_cellmate
    wapstatelessSessionBeans_WapCMEntranceBean.java:65)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_kcp_skel_WapCMEntrance.exec
    ute__com_valis_util_ACmdResults__com_valis_util_LogicalCmdParams__127782180(
    ejb_kcp_skel_WapCMEntrance.java:219)
    at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
    at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
    at com.kivasoft.ebfp.FPRequest.invoke(Unknown Source)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_kcp_stub_WapCMEntrance.exec
    ute(ejb_kcp_stub_WapCMEntrance.java:328)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_stub_WapCMEntrance.execute(
    ejb_stub_WapCMEntrance.java:71)
    at com.valis.cellmate.servlets.CMServlet.executeCmd(CMServlet.java)
    at
    com.valis.cellmate.servlets.FindIMateHandler.doGetOrPost(FindIMateHandler.ja
    va)
    at com.valis.cellmate.servlets.CMServlet.service(Compiled Code)
    at javax.servlet.http.HttpServlet.service(Compiled Code)
    at com.netscape.server.servlet.servletrunner.ServletInfo.service(Compiled
    Code)
    at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Compiled
    Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Compiled Code)
    at java.lang.Thread.run(Compiled Code)
    Hed Bar-Nissan
    Valis R&D

    i get this exception continuously :
    20010827175301793 ERROR 27 Aug 2001 17:53:01,793 CMServlet :
    java.rmi.NoSuchObjectException: <mapped>
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.io.IOException.<init>(Compiled Code)
    at java.rmi.RemoteException.<init>(RemoteException.java:56)
    at java.rmi.NoSuchObjectException.<init>(NoSuchObjectException.java:50)
    at com.kivasoft.eb.EBExceptionUtility.idToSystem(Unknown Source)
    at com.kivasoft.ebfp.FPUtility.replyToException(Unknown Source)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_kcp_stub_WapCMEntrance.exec
    ute(ejb_kcp_stub_WapCMEntrance.java:356)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_stub_WapCMEntrance.execute(
    ejb_stub_WapCMEntrance.java:71)
    at com.valis.cellmate.servlets.CMServlet.executeCmd(CMServlet.java)
    at
    com.valis.cellmate.servlets.LoginHandler.updateServerOnUserLogin(LoginHandle
    r.java)
    at
    com.valis.cellmate.servlets.BackdoorLogger.doGetOrPost(BackdoorLogger.java)
    at com.valis.cellmate.servlets.CMServlet.service(Compiled Code)
    at javax.servlet.http.HttpServlet.service(Compiled Code)
    at com.netscape.server.servlet.servletrunner.ServletInfo.service(Compiled
    Code)
    at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Compiled
    Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Compiled Code)
    at java.lang.Thread.run(Compiled Code)
    After i get once an unchecked exception :
    20010827175231868 ERROR 27 Aug 2001 17:52:31,869 CMServlet :
    com.netscape.server.eb.UncheckedException: unchecked exception thrown by
    impl [email protected]513cb;
    nested exception is:
    java.lang.NullPointerException
    java.lang.NullPointerException
    at
    com.valis.cellmate.wap.statelessSessionBeans.WapCMEntranceBean.execute(WapCM
    EntranceBean.java)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_skel_com_valis_cellmate_wap
    statelessSessionBeansWapCMEntranceBean.execute(ejb_skel_com_valis_cellmate
    wapstatelessSessionBeans_WapCMEntranceBean.java:65)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_kcp_skel_WapCMEntrance.exec
    ute__com_valis_util_ACmdResults__com_valis_util_LogicalCmdParams__127782180(
    ejb_kcp_skel_WapCMEntrance.java:219)
    at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
    at com.kivasoft.ebfp.FPRequest.invokenative(Native Method)
    at com.kivasoft.ebfp.FPRequest.invoke(Unknown Source)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_kcp_stub_WapCMEntrance.exec
    ute(ejb_kcp_stub_WapCMEntrance.java:328)
    at
    com.valis.cellmate.wap.statelessSessionBeans.ejb_stub_WapCMEntrance.execute(
    ejb_stub_WapCMEntrance.java:71)
    at com.valis.cellmate.servlets.CMServlet.executeCmd(CMServlet.java)
    at
    com.valis.cellmate.servlets.FindIMateHandler.doGetOrPost(FindIMateHandler.ja
    va)
    at com.valis.cellmate.servlets.CMServlet.service(Compiled Code)
    at javax.servlet.http.HttpServlet.service(Compiled Code)
    at com.netscape.server.servlet.servletrunner.ServletInfo.service(Compiled
    Code)
    at com.netscape.server.servlet.servletrunner.ServletRunner.execute(Compiled
    Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.applogic.AppLogic.execute(Compiled Code)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Native Method)
    at com.kivasoft.thread.ThreadBasic.run(Compiled Code)
    at java.lang.Thread.run(Compiled Code)
    Hed Bar-Nissan
    Valis R&D

  • Find all unchecked exceptions thrown by method?

    Dear all,
    I am writing critical code that must be correct. Thus, I wish to know that I have not overlooked any important unchecked exceptions. I am aware that the distinction between unchecked and checked exceptions is controversial, and I know the difference between these types of exceptions.
    I would like to see for each function a list of all possible exceptions a method can throw. Preferably I would like a tool to do this for me, but I would write something myself if there is a reasonably simple way to do it.
    More precisely, I would like to be able to define the set of "unchecked" exceptions myself, e.g., I would put down NullPointerException as "unchecked", but I would let IOException be checked (in my particular application, not in general). In general, this would however be a very nice language feature that could perhaps be a compromise in the (un)checked exceptions-controversy. Each programmer could define an "unchecked"-filter. Perhaps it would best be viewed as a kind of lint.
    In any case, I have not found any tool, and it seems I can not do it myself with reflection, since it only gives access to declared exceptions, i.e., if the JDK-programmer decided not to put IOException in the signature of a method, then reflection can not see that the method may throw such an exception.
    Does anybody know how to do this?

    Douglas1024 wrote:
    Thank you for your time, but I am well aware how one uses exceptions in normal code.
    From an abstract point of view exceptions are simply a form of outputs from a method. Thus, if the goal is to write correct and easily verifiable code, in contrast to the vast majority of code that simply works reasonably, it is quite meaningful to know exactly what kinds of exceptions are thrown by a method and when.
    Please note my correction regarding IOException.Millions upon millions of lines of correct code have been written following these standard java exception principles. The notion that you can write "better" code by detailing every single unchecked exception that could possibly be thrown is ludicrous. In fact by handling unchecked exceptions you will in all likelihood do more harm than good, hence why they are unchecked in the first place.

  • Using an unchecked exception to alter flow control inside a class

    Best-practice question:
    Is it wrong to use an unchecked exception in an if-like manner?
    For example, instead of using:
    if (condition) {
    -----------a lot of code-----------------
    } else {
    ----------some more code--------------
    Is it wrong to do it like this?
    try {
    if (!condition) throw new IllegalArgumentException();
    -------------a lot of code---------------
    } catch (IllegalArgumentException e) {
    --------------some more code-----------
    I'm asking because I used this kind of practice recently in a piece of code i wrote (actually i used it to validate an argument I received from a html-form and post an error message in the catch block) and a colleague told me it was bad practice.
    If it IS bad practice, when should you actually use unchecked exceptions like IllegalArgumentException?
    I already posted this question in the newbie forum, but didn't get any answers. Anybody here can explain this to me please?

    It is fine to use IllegalArgumentException, but typically it is used when the code generating the exception and the client who is using the code that generates the exception are two different pieces of code.
    If you were writing some kind of library for others to use. It would make sense to throw this exception out of your library if the user gave you wrong data.
    But you shouldn't use exceptions as normal program logic.

  • Unchecked Exception Handling in an Applet

    What happens in a multithreaded applet when you get an unchecked exception (Array out of Bounds)?
    Where does control pass after the stack trace? Are threads that are not in the exception code path still running?
    Yes, I have fixed the out of bounds errors, but I am investigating where subsequent behavior may be the result of the exception or a race condition.

    An unhandled Exception terminates execution of the current thread. Other executing threads are not directly effected by the uncaught Exception (and subsequent termination).
    Any locks help by the thread should be released once control passes out of the run method (due to the Exception).

  • Unchecked exception

    hi all...
    can throws be used to avoid unchecked exception???
    for example,,,,,in this c ode throws is not able to handle unchecked exception i.e. arithmetic exception.....
    public class Test {
    public static void main(String[] args) throws ArithmeticException{
    int a=1,b=0,c;
    c=a/b;
    System.out.println(c);
    but This code is working fine ,,,when i am using try catch to handle this exception
    public class test1 {
    public static void main(String[] args) {
    try{
    int a=1,b=0,c;
    c=a/b;
    System.out.println(c);}
    catch(ArithmeticException e)
    System.out.println("error occured");
    ..........................

    The throws clause doesn't handle an exception, it warns the caller of the method that there's a checked exception that the code that calls it needs to deal with.
    Unchecked exceptions (e.g zero divide) are usually not handled, they typically cause the program to abnormally terminate. That's because, as a general rule, an unchecked exception means there's something wrong with the program so what's the point of continuing?
    A checked, exception, on the other hand, usually indicates that there's something wrong with the program's environment. A data file is missing or has the wrong format, the user has entered something other than a number where a number is expected or something of that kind, and it often makes sense for the program to try and recover (e.g. by asking for the data again).

  • Convert checked exception into unchecked exception

    Hi friends
    I am little confused, When deciding on checked exceptions vs. unchecked exceptions. I went through the net. they are telling that
    Use checked exceptions when the client code can take some useful recovery action based on information in exception. Use unchecked exception when client code cannot do anything.
    Here what is the client code. which is the best way is checked exception good or is unchecked exception good or shall i simply tell catch(Exception e){...} or do i have to tell the particular exception like catch(SQLException) {..} instead of mentioning catch(excetpion){....}. I am so much confused...
    Could you please tell me how to convert this code from checked exception into unchecked exception.
    Connection con = null;
    try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
         "root", "sheik");
         if(!con.isClosed())
         System.out.println("Successfully connected to " +
         "MySQL server using TCP/IP...");
         PreparedStatement ps = con.prepareStatement("DELETE FROM EMPLOYEE WHERE ID=?");
         ps.setInt(1, 3);     
         System.out.println(ps.executeUpdate());
         } catch(Exception e) {
         System.err.println("Exception: " + e.getMessage());
         } finally {
         try {
         if(con != null)
         con.close();
         } catch(SQLException e) {
              System.out.println(e);
    Thanks and Regards
    Sherin Pooja

    pierrot_2 wrote:
    I think the words CHECKED and UNCHECKED are misleading.How so? Checked exceptions are those that are checked for by the compiler--requiring either catch or declare, and unchecked exceptions are those that the compiler doesn't check for and hence can be thrown anywhere without a catch or declare.
    When a program can't deal with a situation at all, subclasses of <tt>Error</tt> are thrown and the program should terminate. When a program should continue to run, despite an anomaly of some sort, then programs should throw subclasses of <tt>Exception</tt>.No.
    When there's a normal exceptional condition that can't be avoided simply by good coding--loss of network connection, disk full, insufficient permissions for an operatiion, and so on--throw a checked exception, that is, a subclass of Exception that is not a subclass of RuntimeException, such as IOExceptoin.
    When there's a bug in your code, or in the caller of your code, or in some other code that you use, such as not ensuring preconditions are met, throw RuntimeException or a subclass. These are all unchecked. You generally do not catch these except at major layer boundaries.
    When there's an internal error that the JVM has a good chance of not being able to recover from, such as running out of memory, Error or one of its subclasses is thrown. These are also unchecked, and it's pretty rare to explicitly throw one of these from code that you write. You generally do not catch these, except at major layer boundaries, and even then, probably in fewer situations than when you'd catch RuntimeException.

  • Unchecked exceptions in web services

    Hi all.
    How are unchecked exceptions handled in web services ? Are they automatically mapped as SOAPFaults in the SOAP return message ?

    With JAX-WS and JAX-RPC , yes.

  • Unchecked Exceptions in JCO

    Can anyone provide some insight into why all exceptions in JCO are unchecked exceptions?  It puts an additional burden on the users of this library that Java programmers are accustomed to having enforced for them by the compiler.
    Thanks

    With JAX-WS and JAX-RPC , yes.

  • Checked or Unchecked Exceptions

    I've had people explain the differences of checked exceptions and unchecked exceptions but I just can't seem to get it into my head. Can anyone help explain what the differences are?

    Exceptions: Most programs throw and catch objects that derive from the Exception class. Exceptions indicate
    that a problem occurred but that the problem is not a serious JVM problem. An Exception class has many
    subclasses. These descendants indicate various types of exceptions that can occur. For example,
    NegativeArraySizeException indicates that a program attempted to create an array with a negative size. One
    exception subclass has special meaning in the Java language: RuntimeException. All the exceptions except
    RuntimeException are compiler checked exceptions. If a method is capable of throwing a checked exception it
    must declare it in its method header or handle it in a try/catch block. Failure to do so raises a compiler error. So
    checked exceptions can, at compile time, greatly reduce the occurrence of unhandled exceptions surfacing at
    runtime in a given application at the expense of requiring large throws declarations and encouraging use of poorlyconstructed
    try/catch blocks. Checked exceptions are present in other languages like C++, C#, and Python.
    Runtime Exceptions (unchecked exception)
    A RuntimeException class represents exceptions that occur within the Java virtual machine (during runtime). An
    example of a runtime exception is NullPointerException. The cost of checking for the runtime exception often
    outweighs the benefit of catching it. Attempting to catch or specify all of them all the time would make your code
    unreadable and unmaintainable. The compiler allows runtime exceptions to go uncaught and unspecified. If you
    like, you can catch these exceptions just like other exceptions. However, you do not have to declare it in your
    �throws" clause or catch it in your catch clause. In addition, you can create your own RuntimeException
    subclasses and this approach is probably preferred at times because checked exceptions can complicate method
    signatures and can be difficult to follow.

  • Checked & Unchecked Exceptions

    What are Checked and UnChecked Exceptions.
    When is it advisable to throw either of these.Can any one give me an example on these.

    If an exception is "checked", you'll get a compiler
    error if you don't catch it; if it's
    "unchecked", you won't. Unchecked exceptions are
    always subclasses of Error or RuntimeException.
    Why have unchecked exceptions? If it were necessary
    to catch NullPointerException and
    ArrayIndexOutOfBoundsException every time one accessed
    an array element, there would be very few Java
    programmers.This is a very old post which I was browsing through. It wont be of much of an interest to anybody but to set the recoed straight for anybody who goes through it. RuntimeExceptions are also subclasses of Exception and secong unchecked Exceptions are not subclasses of Error.

  • Checked and unchecked exception

    what is the differance between the checked and unchecked ecxeption.

    Any exception deriving from RuntimeException (which is a sublclass of Exception) is unchecked.
    All other exceptions derived from Exception class are checked ones.
    Checked exceptions are indicated by the throws clause. But unchecked exceptions are not.
    An example of unchecked exception is NullPointerException.
    A programmer should not write code to catch unchecked exceptions.

  • Unchecked Exception using 1.5 Concurrent Libraries

    Sorry to post this here, but it IS related to generics. I'm either doing something wrong, or the concurrent libraries are missing some methods in the ThreadPoolExecutor class.
    I'll try and be brief. When I compile my multi-threaded application with lint on, I get the following error:
    "TransactionsByStore.java:309: warning: [unchecked] unchecked conversion
    found : java.util.concurrent.LinkedBlockingQueue
    required: java.util.concurrent.BlockingQueue<java.lang.Runnable>
    threadPool = new ThreadPoolExecutor(threadCount, threadCount, threadTimeout, TimeUnit.SECONDS, threadQueue);"
    The problem is my "threadQueue" class. It is of type LinkedBlockingQueue<java.util.concurrent.Callable> since Callable allows the class to return something from the "call" method. It appears that most classes in the concurrent libraries prefers Callable classes over Runnable, but the constructor for a ThreadPoolExecutor appears to only accept a thread queue that holds Runnables. That doesn't seem correct.
    Does anyone know if there is something that I am doing wrong here, or is this just a current limitation of the ThreadPoolExecutor class?
    Thanks.

    The problem is my "threadQueue" class. It is of type
    LinkedBlockingQueue<java.util.concurrent.Callable>
    since Callable allows the class to return something
    from the "call" method. It appears that most classes
    in the concurrent libraries prefers Callable classes
    over Runnable, but the constructor for a
    ThreadPoolExecutor appears to only accept a thread
    queue that holds Runnables. That doesn't seem
    correct.
    Does anyone know if there is something that I am
    doing wrong here, or is this just a current
    limitation of the ThreadPoolExecutor class?OK, so I just did some reading and I now better understand the context of your question:
    * ThreadPoolExecutor is an ExecutorService, not just an Executor, so it handles Callables in addition to Runnables
    * You're taking the slightly unusual step of constructing your own instance, presumably because you've determined none of the predefined ExecutorServices that the Executors factory class creates are suitable for your task?
    * As you wish to use the ThreadPoolExecutor to execute Callables, you want to know why the constructor takes BlockingQueue<Runnable> rather than BlockingQueue<Callable>
    So firstly, this question really has nothing to do with generics. Callable isn't a Runnable and as such there's no way you're ever going to be able to pass a BlockingQueue<Callable> into this method. Therefore it's a question about the design of the concurrency libraries. As such you'll probably get much better quality answers in a forum dedicated to that subject.
    Having said that:
    From what I see the ExecutorService.submit() methods that support Callables are all implemented in the AbstractExecutorService class that is the superclass for ThreadPoolExecutor.
    So I read the source code for that class. Turns out every Callable passed to submit() is wrapped in a FutureTask, which is a class that imlements Future<V> and Runnable. This makes perfect sense if you think about it - given that this ExecutorService executes things asynchronously, clearly a Future<V> is required if you want to be able to actually get at the result.
    Thus since Callables are wrapped in a class that's Runnable inside the ExecutorService, that's how it is able to handle Callables using a BlockingQueue<Runnable>.
    So... is it important to you that the queue you pass in is a BlockingQueue<Callable> or can you simply make it a BlockingQueue<Runnable>?
    You're never going to be able to constrain the type of the BlockingQueue to be anything stricter than Runnable, BTW. This is because the ThreadPoolExecutor executes Runnables as well as Callables, so if you were allowed to pass in a BlockingQueue<FutureResult> (for example) then it wouldn't work because the execute(Runnable) method wouldn't be able to add the Runnable to the queue without wrapping it in a spurious FutureResult.

  • Checked and unchecked Exceptions

    I'm novice(new to java) could anyone please explain it in best way.
    Thanks in advance

    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
    If you're new to Java, start with reading the tutorials (or a Java book):
    http://java.sun.com/docs/books/tutorial/
    -Puce

Maybe you are looking for

  • Share instrument in loops

    Hi, I'm wondering if there's a way to share an instrument panel within multiple loops/cases in labview? Basically I'm trying to get an IV chart based on the test the user selects, the only way I can correctly get this to work is have an individual gr

  • Problem with minimal height of components that renders as DIV in FF

    I noticed this when I wanted to put af:spacer with height less then 10px. In panelGroupLayout (property layout set to vertical) I wanted to set vertical spacing between images to 5px. af:spacer that renders as img (width:1px / height:5px) was in DIV

  • How to get automatically batch no in delivery level?

    Dear Expert How to get automatically batch no in delivery level? Thanks for Advance

  • How can I set family sharing with my mom living in Europe?

    hi, i just bought new iphone for my mom who is living in Europe and I wanted to set family sharing with her to share pictures but I can't because I live in USA ... is there any way how to set it? Thanx

  • Case function with group by

    Hi,   I am having a scenario like : Column 1:  BrokerList(dimension1) Column 2 : Broker(dimension2) Column 3 : Metric value(measure) so i am having a case when (dimension 3) Custodian = 'ss' then sum(metirc) group by dimension1,dimension2 but the res