Web Article - Quartz HelloWorld Example

pom.xml:


 4.0.0
 com.javacodegeeks.snippets.enterprise
 quartzexample
 0.0.1-SNAPSHOT

 
  
   org.quartz-scheduler
   quartz
   2.2.1
  
 


MyApp.java
package com.javacodegeeks.snippets.enterprise.quartzexample;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import com.javacodegeeks.snippets.enterprise.quartzexample.job.ByeJob;
import com.javacodegeeks.snippets.enterprise.quartzexample.job.HelloJob;

public class MyApp {

 public static void main(String[] args) {
  try {
   JobDetail job1 = JobBuilder.newJob(HelloJob.class).withIdentity("helloJob", "group1").build();

   Trigger trigger1 = TriggerBuilder.newTrigger().withIdentity("simpleTrigger", "group1")
     .withSchedule(SimpleScheduleBuilder.repeatSecondlyForTotalCount(30)).build();   
   Scheduler scheduler1 = new StdSchedulerFactory().getScheduler(); 
   scheduler1.start(); 
   scheduler1.scheduleJob(job1, trigger1); 
   
   JobDetail job2 = JobBuilder.newJob(ByeJob.class).withIdentity("byeJob", "group2").build();
   Trigger trigger2 = TriggerBuilder.newTrigger().withIdentity("cronTrigger", "group2")
     .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).build();
   Scheduler scheduler2 = new StdSchedulerFactory().getScheduler();
   scheduler2.start(); 
   scheduler2.scheduleJob(job2, trigger2); 
   }
  catch(Exception e){ 
   e.printStackTrace();
  }
 }

}

Source: javacodegeeks

Web Article - Tomcat DataSource JNDI Example


APACHE_TOMCAT_DIR/conf/context.xml:

< Resource auth="Container" 
driverClassName="com.mysql.jdbc.Driver" 
maxActive="100"  maxIdle="30" maxWait="10000"
name="jdbc/TestDB" type="javax.sql.DataSource" 
url="jdbc:mysql://localhost:3306/jcg?rewriteBatchedStatements=true" 
username="username"  password="password" />
web.xml:

MySQL Datasource example 
jdbc/TestDB 
javax.sql.DataSource 
Container 


DBConnection.java:
package com.javacodegeeks.examples;


import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


/**
 * @author Chandan Singh
 */
public class DBConnection
{
 public static Connection getConnection() throws SQLException, ClassNotFoundException, NamingException
 {
  Context ctx = new InitialContext();
  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
  Connection connection = ds.getConnection();
                System.out.println(connection);

  return connection;
 }
}




Source: javacodegeeks.com

Oracle Exam - Java SE 7 Programmer I | 1Z0-803


Exam Number :1Z0-803
Associated Certifications:Oracle Certified Associate, Java SE 7 Programmer
Duration:120 minutes
Number of Questions:70
Passing Score63% View passing score policy


Resources:
Book: OCA/OCP Java SE 7 Programmer I & II Study Guide

Web Article - Top 10 Best free Rich Text Editors


1) Best Rich Text Editor – NicEdit


2) Rich Text Editor – Xinha
3) Free Rich Text Editor – WYSIWYG Editor
4) Best Web Text Editor- FCKeditor
5) Best Javascript Markup Editor – MarkITUp
6) Rich Text Editor – WidgEditor
7) Best Leading Text Editor – XStandard
8) Free Web Based Text Editor – Whizzywig
9) Best Web based XHTML Editor – WYMeditor
10) Top free Rich Text Editor – FreeTextBox

Source: Devzum.com

Video - How to Develop Realtime Chat Room Application on Android

Demo Android chat room application using AppWarp which is our realtime multiplayer network cloud engine.


About Appwarp

Web Article: Java Synchronized keyword Example

Example 1

package com.javacodegeeks.snippets.core.synchronizedexample;

import java.util.ArrayList;

public class SynchronizedMethodClass {

 private ArrayList < Integer > nums1;
 private String pos1;

    public SynchronizedMethodClass() {
     nums1 = new ArrayList < Integer >();
     nums1.add(0);
     pos1 = "0";
    }

 public ArrayList < Integer > getNums1() {
  return nums1;
 }

 public void setNums1(ArrayList < Integer > nums1) {
  this.nums1 = nums1;
 }

 public String getPos1() {
  return pos1;
 }

 public void setPos1(String pos1) {
  this.pos1 = pos1;
 }

 public synchronized void syncMethod(String threadName) {
     Integer number = nums1.get(nums1.size() - 1) + 1;
        pos1 = String.valueOf(number);
        nums1.add(number);
        System.out.println("Thread " + threadName + " : " 
+ nums1.get(nums1.size() - 1) + " - " + pos1);
    }
}
Example 2
package com.javacodegeeks.snippets.core.synchronizedexample;

import java.util.ArrayList;

public class SynchronizedBlockClass {

    private ArrayList < Integer > nums2;
    private String pos2;
    private int counter;
    
    public SynchronizedBlockClass() {
     nums2 = new ArrayList < Integer >();
     nums2.add(0);
     pos2 = "0";
    }
 
 public ArrayList < Integer > getNums2() {
  return nums2;
 }

 public void setNums2(ArrayList < Integer > nums2) {
  this.nums2 = nums2;
 }
 
 public String getPos2() {
  return pos2;
 }

 public void setPos2(String pos2) {
  this.pos2 = pos2;
 }

 public int getCounter() {
  return counter;
 }

 public void setCounter(int counter) {
  this.counter = counter;
 }

    public void syncBlock(String threadName) {
     counter++;
     System.out.println("Thread " + threadName + " - counter: " + counter);
        synchronized (this) {
         Integer number = nums2.get(nums2.size() - 1) + 1;
            pos2 = String.valueOf(number);
         nums2.add(number);
            System.out.println("Thread " + threadName + " Added to list: " 
              + nums2.get(nums2.size() - 1) + " - " + pos2);
           }
    }

}

Source: javacodegeeks

Powered by Blogger