Tuesday, 27 May 2014

ScheduledThreadPoolExecutor example

package mypackage;
import java.text.DateFormat;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ScheduledExample {
    final static DateFormat fmt = DateFormat.getTimeInstance(DateFormat.LONG);
    public static void main(String[] args) {
        // Create a scheduled thread pool with 5 core threads
        ScheduledThreadPoolExecutor sch = (ScheduledThreadPoolExecutor)
                Executors.newScheduledThreadPool(5);
        
        // Create a task for one-shot execution using schedule()
        Runnable oneShotTask = new Runnable(){
            @Override
            public void run() {
                System.out.println("\t oneShotTask Execution Time: "
                            + fmt.format(new Date()));
            }
        };
        
        // Create another task
        Runnable delayTask = new Runnable(){
            @Override
            public void run() {
                try{
                    System.out.println("\t delayTask Execution Time: "
                            + fmt.format(new Date()));
                    Thread.sleep(10 * 1000);
                    System.out.println("\t delayTask End Time: "
                            + fmt.format(new Date()));
                }catch(Exception e){
                    
                }
            }
        };
        
        // And yet another
        Runnable periodicTask = new Runnable(){
            @Override
            public void run() {
                try{
                    System.out.println("\t periodicTask Execution Time: "
                            + fmt.format(new Date()));
                    Thread.sleep(10 * 1000);
                    System.out.println("\t periodicTask End Time: "
                            + fmt.format(new Date()));
                }catch(Exception e){
                    
                }
            }
        };
        
        System.out.println("Submission Time: " + fmt.format(new Date()));
    //  ScheduledFuture<?> oneShotFuture = sch.schedule(oneShotTask, 5, TimeUnit.SECONDS);
      ScheduledFuture<?> delayFuture = sch.scheduleWithFixedDelay(delayTask, 5, 5, TimeUnit.SECONDS);
     //   ScheduledFuture<?> periodicFuture = sch.scheduleAtFixedRate(periodicTask, 5, 5, TimeUnit.SECONDS);
    }
}

Friday, 16 May 2014

How to generate Java Doc

Java Doc can be generated using Eclipse IDE.We should have Javadoc.exe in the bin folder of the Java

Following is the step

Go to Eclipse--------->Project Menu--------->Generate Java Doc--------->Here you will be prompted with the menu which contains all the projects present in IDE , select the project for which you want JavaDoc.

Above give the following location C:\Program Files\Java\jdk1.7.0_17\bin\javadoc.exe


Click on next.Select the location where uou want the java doc's to be extracted.

Done:)

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...