2010년 4월 5일 월요일

quartz

퍼온글:

http://www.easywayserver.com/blog/java-job-scheduling-in-web-application-with-quartz-api/


Java – Job Scheduling in web application with quartz API

Scheduling job in web application is important part of application. Today most of the companies and programmer keep eye on the performance of the application. They do it by running most of work in background of the application without the knowledge of the user. Manual work is going to automize in these days and run in idle time of working hours.

If you want to send email at fixed time, send newsletter, taking backup of database, synchronizing of databases, setting up reminder, all need to run schedule job at particular interval.

Java is bundled with timer class to perform scheduling task and make your own logics to perform scheduling by while loop with sleep thread. But this is not good way to schedule more than one job at a time.

Timer class is good option for scheduling task, but it still doesn’t have optional day selection like in cron of linux.

Quartz is scheduling API which fulfill your all need and easy to use and initialization of scheduling.

We can use simple trigger with millisecond and repeat jobs and set repeat intervals. Advance Trigger CronTrigger works exactly same unix cron. In CronTrigger we can define, selected days e.g. Wednesday, Friday weekly, monthly and yearly.

In quartz, we can monitor our jobs and in between can stop jobs.

Quartz scheduling can be used with servlet initialization and struts initialization.

In servlet initialization, we have to define in web.xml and in struts we have to define plugin in struts-config.xml.

1. Quartz with Simple Servlet

web.xml

<web-app>
<display-name>timer</display-name>

<servlet>
<servlet-name>InitializeServlet</servlet-name>
<servlet-class>com.cron.InitializeServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

</web-app>

InitializeServlet.java

package com.cron;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class InitializeServlet extends HttpServlet {

public void init() throws ServletException {

try {
System.out.println("Initializing NewsLetter PlugIn");

CronScheluder objPlugin = new CronScheluder();

}
catch (Exception ex) {
ex.printStackTrace();
}

}

}

CronScheluder.java

package com.cron;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

public class CronScheluder {

public CronScheluder() throws Exception {

SchedulerFactory sf = new StdSchedulerFactory();

Scheduler sche = sf.getScheduler();

sche.start();

JobDetail jDetail = new JobDetail("Newsletter", "NJob", MyJob.class);

//"0 0 12 * * ?" Fire at 12pm (noon) every day
//"0/2 * * * * ?" Fire at every 2 seconds every day

CronTrigger crTrigger = new CronTrigger("cronTrigger", "NJob", "0/2 * * * * ?");

sche.scheduleJob(jDetail, crTrigger);
}
}

MyJob.java

package com.cron;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class MyJob implements Job {

public void execute(JobExecutionContext context)
throws JobExecutionException {

System.out.println("Cron executing ");

}
}

Another option to use quartz api

2. Quartz with ServletContextListener

web.xml

<web-app>

<display-name>timer</display-name>

<listener>
<listener-class>com.cron.StartCron</listener-class>
</listener>

</web-app>

StartCron.java

package com.cron;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class StartCron implements ServletContextListener{

public void contextDestroyed(ServletContextEvent arg0)
{
System.out.println("Stopping Application successfully");
}

public void contextInitialized(ServletContextEvent arg0)
{
System.out.println("Initializing Application successfully");

try{
CronScheluder objPlugin = new CronScheluder();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

All rest of code is same and use

CronScheluder.java

MyJob.java

3. Quartz with Struts

You have to define in struts-config.xml file a plugin

 <plug-in className="com.cron.StrutsImp">
<set-property property="startOnLoad" value="true"/>
<set-property property="startupDelay" value="0"/>
</plug-in>

StrutsImp.java

package com.cron;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

public class StrutsImp implements PlugIn {

public static final String PLUGIN_NAME_KEY = StrutsImp.class.getName();

public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException {

try {
System.out.println("Initializing PlugIn");

ServletContext context = null;

context = servlet.getServletContext();

CronScheluder objPlugin = new CronScheluder(context);

context.setAttribute(PLUGIN_NAME_KEY, objPlugin);

System.out.println("scheluder started successfully...");

}
catch (Exception ex) {
ex.printStackTrace();
}

}

public void destroy()
{

}

}

2010년 4월 3일 토요일

VisualSVN

1. 파일 다운로드

 

a. 서버용 프로그램 : VisualSVN-Server

b. 클라이언트 프로그램 : TortoiseSVN / 한 글 언어팩

c. CommitMonitor (Commit 알림기능)

 

2. 서버 설치

 

a. Select Components : VisualSVN Server and Management Console

b.  Custom Setup

- Location : 프로그램 설치 폴더

- Repositories : 저장소 폴더

- Sever Port : https포트 (Use secure connection 체크)

- Authentication : "서브버전 계정" 또는 "윈도우 계정" 선택

 

3. HTTPS 동작확인

 

a. 익스플로러 실행하여 주소칸에 https://localhost/ 입력

b. "이 웹 사이트를 계속 탐색합니다.(권장하지 않음)" 선택

c. 로그인

 

4. 사용자 등록

 

a. VisualSVN-Server Manager 실행

b. 프로그램 우측의 User 폴더 우클릭하여 "Create User" 실행

c. 사용자ID 및 비밀번호 입력 후 "OK"

 

5. 저장소 생성

 

a. 프로그램 우측의 Repositories 폴더 우클릭하여 "Create New Repository" 실행

b. 저장소 이름입력

(Create default structure 체크시 "trunk", "branches", "tags" 3개의 폴더가 기본 생성됨)

 

6. 백업

a. 백업

# svnadmin dump 저장소절대경로 > 덤프파일
예) svnadmin dump C:\svn_root\project > project.dump
b. 저장소 생성

# svnadmin create 새로만들저장소절대경로
예) svnadmin create  C:\svn_root\project2

c. 복구

# svnadmin load 새로만들저장소절대경로 < 덤프파일명
예) svnadmin load C:\svn_root\project2 < project.dump

[출처] VisualSVN|작성자 푸우님


2010년 4월 2일 금요일

flash post 방식

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=10402&docId=68350639&qb=Zmxhc2ggcG9zdA==&enc=utf8&section=kin&rank=4&sort=0&spq=1&pid=fJU8ng331y0sscBrbxKssv--300024&sid=S7X8PQOztUsAAHjrD8A


============= 플래시 부분 ==============

 rewriteObj = new LoadVars();
 rewriteObj.num = this.num;
 rewriteObj.sendAndLoad(" 호출할파일주소(*.asp)", rewriteObj, "post");
 rewriteObj.onLoad = function() {
  if (this.result == "ok") {
   trace("1을 받았습니다.")
  } else {

trace("1을받지 않았습니다.")
    }

 

==================== asp 부분 =================

num = request("num")

if num = "1" then

response.write "&result=ok"

else

response.write "&result=fail"

end if


2010년 3월 10일 수요일

Catmull-Rom Spline

보간 - Catmull-Rom Spline
http://www.gisdeveloper.co.kr/archive/200902#entry_468

double catmullRomSpline(float x, float v0,float v1, float v2,float v3) {  
    double c1,c2,c3,c4;  
 
    c1 = M12*v1;  
    c2 = M21*v0 + M23*v2;  
    c3 = M31*v0 + M32*v1 + M33*v2 + M34*v3;  
    c4 = M41*v0 + M42*v1 + M43*v2 + M44*v3;  
 
    return(((c4*x + c3)*x +c2)*x + c1);  

2010년 3월 3일 수요일

리눅스 파일 검색

출처 : http://lbjcom.net/tag/%ED%8C%8C%EC%9D%BC%20%EA%B2%80%EC%83%89

문자열찾기 방법 1 - 영어만 주로 가능
grep -rw "찾는문자열" ./

문자열찾기 방법 2 - 대/소문자 구분 안하고 검색
grep -i -l "찾는문자열" * -r 2> /dev/null

문자열찾기 방법 3 - 한글, 영어 모두 가능
find . -exec grep -l "찾는문자열" {} \; 2>/dev/null

문자열찾기 방법 4 - 한글,영어, 대소문자 안가리고 검색
find . -exec grep -i -l "찾을문자열" {} \; 2>/dev/null

문자열찾은 후 치환
find . -exec perl -pi -e 's/찾을문자열/바꿀문자열/g' {} \; 2>/dev/null

파일명 찾기
find / -name 파일명 -type f

파일명 찾기(대소문자 구별없음)
find / -iname 파일명 -type f

디렉토리 찾기
find / -name 파일명 -type d

디렉토리 찾기(대소문자 구별없음)
find / -iname 파일명 -type d 

[출처] 리눅스 파일 검색|작성자 두한

2010년 2월 9일 화요일

find bugs

 

버그의 가능성이 있는 코드를 검출

 

LGPL 기반 오픈소스

 

http://findbugs.sourceforge.net/

 

이클립스 플러그인 업데이트

http://findbugs.cs.umd.edu/eclipse/