What is the most simple way to execute java class every 30 seconds

Posted by Gandalf StormCrow on Stack Overflow See other posts from Stack Overflow or by Gandalf StormCrow
Published on 2010-03-19T10:04:34Z Indexed on 2010/03/19 10:11 UTC
Read the original article Hit count: 232

I've been reading about java/spring/hibernate and worked trough a "dummy" examples so I told my friend to recommend something a bit harder for me, and now I'm stuck.. here is the simplest class I could think of

package spring.com.practice;

public class Pitcher {

    private String shout;

    public String getShout() {
        return shout;
    }

    public void setShout(String shout) {
        this.shout = shout;
    }

    public void voice()
    {
        System.out.println(getShout());
    }

}

What is the most simple way to print out something by calling metod voice() from spring beans, and do it repeadatly every 30 seconds lets say, here is what I've got so far :

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="jobSchedulerDetail" />
    <property name="startDelay" value="0" />
    <property name="repeatInterval" value="30" />
</bean>


<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="schedulerName" value="pitcherScheduler" />
    <property name="triggers">
        <list>
            <ref bean="simpleTrigger" />
        </list>
    </property>
</bean>
 <bean id="pitcher" class="spring.com.practice.Pitcher">
 <property name="shout" value="I started executing..."></property>
 </bean>

And yes I'm trying to run this on Jboss 5, I'm building a project with maven.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring