How to set Server Time for ScheduledTimerTask in spring?

We are using ScheduledTimerTask to manage the jobs(automatic) in our application.We are using the following code:

<bean id="SampleTask" 
    <property name="targetObject" ref="sampleScheduler" />
    <property name="targetMethod" value="runMethod" />

<bean id="sampleScheduler" class="com.sample.SampleScheduler" />

<bean id="timerTask"
    <property name="timerTask" ref="schedulerTask" />
    <property name="delay" value="1000" />
    <property name="period" value="60000" />

<bean class="org.springframework.scheduling.timer.TimerFactoryBean">
    <property name="scheduledTimerTasks">
            <ref local="timerTask" />

By using the above code runMethod is working fine for every one minute.But we would like to change the execution based on server time.For example,If time in server is 6 PM then we need to invoke the function.How to achieve it?

Help would be appreciated.


You can use task trigger of Spring to invoke at a certian time period, you can use CronTrigger.

Detailed documentation is here

If you have to use only ScheduledTimerTask, then invoke the timer task once a minute. Now from within the timer task, check if the time is 6AM and run the necessary functionality. Else return.

Con: This task which is NO-OP will get executed for every minute(except for once it has to do some processing.


Invoke the TimeTask only once from the spring. When the task is executed, you can get the current time and can compute the difference between current time and time to execute the actual task. (let this difference be called DELAY).

Now from with in this timer task, start a new Executor Executors.newScheduledThreadPool(1) and scheduleAtFixedRate with intial delay = DELAY and set the period as 1 day

Need Your Help

Android to WCF using JSON 400 bad request and null pointer

android wcf nullpointerexception bad-request

I'm trying to save some information from a user that is saved on the android phone to a WCF service. I'm getting a 400 error from the phone and when I try to send the same request to the server using

Slow response from autocomplete

java swing autocomplete jtextarea swingx

I have applied an auto-complete functionality to two textFields. For this I used AutocompleteDecorator. I have observed it slowing down to the point where I am unable to even enter a single chara...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.