<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d1074803565153692547\x26blogName\x3dInnoLearning\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://innolearning.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://innolearning.blogspot.com/\x26vt\x3d2174717628392424844', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

InnoLearning

Asynchronous Call in Java
Tuesday, July 30, 2013

The java.util.concurrent.ExecutorService interface represents an asynchronous execution mechanism which is capable of executing tasks in the background. An ExecutorService is thus very similar to a thread pool. In fact, the implementation of ExecutorService present in the java.util.concurrentpackage is a thread pool implementation:

   /**
     * Asynchronous call to invoke any method
     * * *
     * @author Manesh Abhimanyu
     * @param String Input 1
     * @param String Input 2
     */
    public void asyncServiceMethod( final String input1, final String input2)
    {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        try {
            Runnable task = new Runnable(){
                public void run()
                {
                    try {
                        invokeMyMethod( input1, input2 );
                    } catch ( Exception ex ) {
                          // handle error which cannot be thrown back
                    }
                }
            };
            executor.execute( task );
        } catch ( Exception e ) {
            // handle error which cannot be thrown back
        }  finally {
            // gargabe collect
            executor.shutdown();
        }
    }






More reading:
Service Execute API


Labels: , , , , , ,

posted by MIGHTYMAK @ 11:52 PM, ,