Updates from November, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 3:29 pm on November 4, 2010 Permalink |
    Tags: , , , ,   

    Today’s read – How To Build A Mobile Website 

    This one is really helpful. How To Build A Mobile Website. This article talks about the stylesheets, mobile stylesheets, customizing them, how to reduce the bandwidth usage and handling iPad/iPhone.

    Over the past few years, mobile web usage has considerably increased to the point that web developers and designers can no longer afford to ignore it. In wealthy countries, the shift is being fueled by faster mobile broadband connections and cheaper data service.  However, a large increase has also been seen in developing nations where people have skipped over buying PCs and gone straight to mobile.

    Unfortunately, the mobile arena introduces a layer of complexity that can be difficult for developers to accommodate.  Mobile development is more than cross-browser, it should be cross-platform.  The vast number of mobile devices makes thorough testing a practical impossibility, leaving developers nostalgic for the days when they only had to support legacy browsers.

    Source: Smashing Magazine

    Read the article

     
  • Subinkrishna Gopi 3:46 pm on February 25, 2010 Permalink |
    Tags: , , , ,   

    Today’s read: The seven deadly sins of JavaScript implementation 

    A Smashing Magazine article on the common “sins” of JavaScript implementation by Christian Heilmann.

    Using JavaScript has become increasingly easy over the last few years. Whereas back in the day we needed to know the quirks of every browser, now many libraries such as jQuery, YUI, Dojo and MooTools allow someone who doesn’t even know JavaScript to spruce up boring HTML documents with impressive and shiny effects. By piggy-backing on the CSS selector engine, we have moved away from the complexity and inconsistencies of the DOM and made things much easier.

    If you look at some of the code that has been released, though, we do seem to have taken a step backwards. In gaining easier access, we also became a bit sloppy with our code. Finding clearly structured, easy-to-maintain jQuery code is quite tough, which is why many plug-ins do the same thing. Writing one yourself is faster than trying to fathom what other developers have done.

    Read the articleFollow the author in twitter !

     
  • Subinkrishna Gopi 3:12 pm on February 19, 2010 Permalink |
    Tags: , executor, , , , thread pool, threadpoolexecutor   

    ThreadPoolExecutor – basics 

    ThreadPoolExecutor is an implementation of the ExecutorService, which can be used to execute the submitted tasks using the available Thread pool. Read the Sun Java API docs for more information.

    The buzz words

    1. Core & max pool size
    This is the size of the core (minimam) and maximum possible thread that need to be in the thread pool every time. We can even specify the keep-alive time limit for the threads.

    2. Work queue
    Work queue is a BlockingQueue, which is used to hold the work/task which is being sent to the executor when all the threads in the pool are busy executing the tasks. Read more about the BlockingQueue in Sun Java API docs.

    3. RejectedExecutionHandler
    So we have a limited number of threads in the pool to execute the tasks and a fixed sized work queue to hold the additional tasks. But what if the work queue overflows! RejectedExecutionHandler can help us in such situations. Read the Sun Java API docs for more.

    Some sample code

    Initializing the ThreadPoolExecutor and sending the task. Here we’ve defined a worksQueue with size 2, core & max pool size is 3 and the threads will expire after 10 seconds. We are also starting a daemon thread to monitor the executor status.

    BlockingQueue<Runnable> worksQueue = new ArrayBlockingQueue<Runnable>(2);
    RejectedExecutionHandler executionHandler = new MyRejectedExecutionHandelerImpl();
    
    // Create the ThreadPoolExecutor
    ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 3, 10,
            TimeUnit.SECONDS, worksQueue, executionHandler);
    executor.allowCoreThreadTimeOut(true);
    
    // Starting the monitor thread as a daemon
    Thread monitor = new Thread(new MyMonitorThread(executor));
    monitor.setDaemon(true);
    monitor.start();
    
    // Adding the tasks
    executor.execute(new MyWork("1"));
    executor.execute(new MyWork("2"));
    executor.execute(new MyWork("3"));
    executor.execute(new MyWork("4"));
    executor.execute(new MyWork("5"));
    executor.execute(new MyWork("6"));
    executor.execute(new MyWork("7"));
    executor.execute(new MyWork("8"));
    
    try
    {
        Thread.sleep(30000);
        executor.execute(new MyWork("9"));
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    

    RejectedExecutionHandler implementation.

    /**
     * The custom {@link RejectedExecutionHandler} to handle the rejected
     * tasks / {@link Runnable}
     */
    public class MyRejectedExecutionHandelerImpl
    implements RejectedExecutionHandler
    {
        @Override
        public void rejectedExecution(Runnable runnable,
                ThreadPoolExecutor executor)
        {
            System.out.println(runnable.toString() + " : I've been rejected ! ");
        }
    }
    

    My task (implements Runnable).

    /**
     * My {@link Runnable} class. Represents a task which need to be executed.
     */
    public class MyWork implements Runnable
    {
        String name;
    
        public MyWork(String name)
        {
            this.name = name;
        }
    
        @Override
        public void run()
        {
            System.out.println(this.name + " : I'm running ! ");
    
            try
            {
                Thread.sleep(5000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
    
            System.out.println(this.name + " : I'm done ! ");
        }
    
        @Override
        public String toString()
        {
            return (this.name);
        }
    }
    

    And the monitor thread.

    /**
     * My monitor thread. To monitor the status of {@link ThreadPoolExecutor}
     * and its status.
     */
    public class MyMonitorThread implements Runnable
    {
        ThreadPoolExecutor executor;
    
        public MyMonitorThread(ThreadPoolExecutor executor)
        {
            this.executor = executor;
        }
    
        @Override
        public void run()
        {
            try
            {
                do
                {
                    System.out.println(
                        String.format("[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s",
                            this.executor.getPoolSize(),
                            this.executor.getCorePoolSize(),
                            this.executor.getActiveCount(),
                            this.executor.getCompletedTaskCount(),
                            this.executor.getTaskCount(),
                            this.executor.isShutdown(),
                            this.executor.isTerminated()));
                    Thread.sleep(3000);
                }
                while (true);
            }
            catch (Exception e)
            {
            }
        }
    }
    

    So we have all necessary code blocks in place. If we execute the above code we may get something like this.

    1 : I'm running !
    2 : I'm running !
    3 : I'm running !
    6 : I've been rejected !
    7 : I've been rejected !
    8 : I've been rejected !
    [monitor] [0/3] Active: 1, Completed: 0, Task: 1, isShutdown: false, isTerminated: false
    [monitor] [3/3] Active: 3, Completed: 0, Task: 5, isShutdown: false, isTerminated: false
    1 : I'm done !
    4 : I'm running !
    2 : I'm done !
    5 : I'm running !
    3 : I'm done !
    [monitor] [3/3] Active: 2, Completed: 3, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [3/3] Active: 2, Completed: 3, Task: 5, isShutdown: false, isTerminated: false
    4 : I'm done !
    5 : I'm done !
    [monitor] [3/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [2/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [2/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [0/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [0/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [0/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    9 : I'm running !
    [monitor] [1/3] Active: 1, Completed: 5, Task: 6, isShutdown: false, isTerminated: false
    [monitor] [1/3] Active: 1, Completed: 5, Task: 6, isShutdown: false, isTerminated: false
    9 : I'm done !
    [monitor] [1/3] Active: 0, Completed: 6, Task: 6, isShutdown: false, isTerminated: false
    [monitor] [1/3] Active: 0, Completed: 6, Task: 6, isShutdown: false, isTerminated: false
    [monitor] [1/3] Active: 0, Completed: 6, Task: 6, isShutdown: false, isTerminated: false
    

     
    • nguyenhuuquan 9:28 pm on April 29, 2013 Permalink

      thanks, it’s helpful. I have a question: if a task take a long time to execute, how to terminate it?

  • Subinkrishna Gopi 3:26 pm on October 13, 2009 Permalink |
    Tags: , , , , , ,   

    How-to: Write web services using Axis2 (Part 2) 

    In my previous post I wrote about writing a web service provider using axis. But I did not mention a few things in that post.

    1. How to make the service accessible to the outside world
    2. How to write a Java client to avail the services

    1. How to make the service accessible to the outside world?

    As we are using the axis2.war as the way to deploy the services, we don’t really need to do anything. The deployment descriptor (web.xml) of axis2.war is equipped to handle it. But we need to make some URL mapping and stuffs like that.

    • Add appropriate URL-servlet mapping  in the web.xml
    • Add the name of the AAR in the service list

    a. Deployment descriptor changes:

     <servlet>
       <servlet-name>AxisServlet</servlet-name>
       <display-name>Apache-Axis Servlet</display-name>
       <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
     </servlet>
    
     <servlet-mapping>
       <servlet-name>AxisServlet</servlet-name>
       <url-pattern>/servlet/AxisServlet</url-pattern>
     </servlet-mapping>
    
     <servlet-mapping>
       <servlet-name>AxisServlet</servlet-name>
       <url-pattern>/services/*</url-pattern>
     </servlet-mapping>
    

    b. Add the name of the AAR in WEB-INF/services/services.list.

    2. Writing a Java client to access the services

    We have several ways to create the client stubs – JiXB, ADB etc. I followed ADB – Axis Data Binding. Axis provides a WSDL2Java tool to create client stubs from an existing WSDL. We can get the WSDL from http://localhost/services/SampleWs?wsdl.

    WSDL2Java -uri SampleWs.wsdl -p subin.rnd.ws.client -d adb -s -o clientStubSrcDirectory_name

    This will create the stub in the specified directory with name SampleWsStub.java. Once the stub is ready, we can write a client module which tries to access the deployed services.

    WsClient.java

    package subin.rnd.ws.client;
    
    import subin.rnd.ws.client.SampleWsStub.WsInput;
    import subin.rnd.ws.client.SampleWsStub.WsOutput;
    
    public class WsClient
    {
     public static void main(String[] args)
     throws Exception
     {
       SampleWsStub stub = new SampleWsStub("http://localhost/services/SampleWs");
    
       // Send the request
       SampleWsStub.DoSomething request = new SampleWsStub.DoSomething();
       WsInput anInput = new WsInput();
       anInput.setName("subin");
       request.setAnInput(anInput);
    
       // Get the response
       SampleWsStub.DoSomethingResponse response = stub.doSomething(request);
       WsOutput anOutput = response.get_return();
    
       System.out.println(anOutput.getResponseString());
     }
    }
    

    And that’s it !!!

     
  • Subinkrishna Gopi 10:47 am on October 6, 2009 Permalink |
    Tags: , , , , , ,   

    Todays read: Mastering CSS Coding 

    Mastering CSS Coding: Getting Started

    An amazingly simple and useful article from Smashing Magazine.

    CSS has become the standard for building websites in today’s industry. Whether you are a hardcore developer or designer, you should be familiar with it. CSS is the bridge between programming and design, and any Web professional must have some general knowledge of it. If you are getting your feet wet with CSS, this is the perfect time to fire up your favorite text editor and follow along in this tutorial as we cover the most common and practical uses of CSS.

    Read it here: http://www.smashingmagazine.com/2009/10/05/mastering-css-coding-getting-started/
    Follow them in twitter

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel