How to synchronized two Timer Task ?

I need to execute 2 job
job1 every sec
job2 every min
when one task is executing other task should wait
so i created 2 timer
timer1 will execute secjob every sec
timer2 will execute minjob every min
and one job object with synchronized execute method
please see the code for further detail
problem:
before completion of secjob , minjob started excuting
job Fired Fri Oct 10 20:45:16 IST 2008 by Timer-0 ID :7.....
job Fired Fri Oct 10 20:45:21 IST 2008 by Timer-0 ID :7.....
job Fired Fri Oct 10 20:45:26 IST 2008 by Timer-0 ID :7....{color:#ff0000}*job Fired Fri Oct 10 20:45:31 IST 2008 by Timer-1 ID :8*{color}*.*
{color:#ff0000}*...*{color}
job Fired Fri Oct 10 20:45:34 IST 2008 by Timer-0 ID :7.....
job Fired Fri Oct 10 20:45:39 IST 2008 by Timer-0 ID :7.....
public class Fire {
    static void secJob(Job job)  {
         Timer timer = new Timer();
         int delay = 0;  
         int period = 1000*1; 
         SecJob secJob = new SecJob(job);
         timer.schedule(secJob, delay, period);        
    static void minJob(Job job) {
         Timer timer = new Timer();
         int delay = 0;  
         int period = 1000*60; 
         MinJob minJob = new MinJob(job);
         timer.schedule(minJob, delay, period);
    public static void main(String[] args) {       
        final Job job = new Job();
        secJob(job);
        minJob(job);
public class SecJob extends TimerTask{
    Job job;
    public SecJob(Job job) {
        this.job = job;
    public void run() {
        job.execute(SecJob.class);
public class MinJob extends TimerTask{
    Job job;
    public MinJob(Job job) {
        this.job = job;
    public void run() {
        job.execute(MinJob.class);   
public class Job {
    private void sleep(long count,PrintStream out) {
        try {
            for (int i = 0; i < count; i++) {
                Thread.sleep(1000*1);
                out.print(".");
            out.println();
        } catch (InterruptedException e) {
            e.printStackTrace();
    public synchronized void execute(Class c) {
        Thread t = Thread.currentThread();
        if(c == MinJob.class ) {
            System.err.print("job Fired "+new Date()+" by "+t.getName()+" ID :"+t.getId());
            sleep(3,System.err);
        }else if(c == SecJob.class ) {
            System.out.print("job Fired "+new Date()+" by "+t.getName()+" ID :"+t.getId());
            sleep(5,System.out);

I'd only use one timer and write a dispatcher task that stores the time at which job2 is executed. If the last time is more than one minute past, execute job1, reset the time tracking field, and execute job2.

Similar Messages

  • Synchronizing the read of two timer tasks (Period and Two Edge Separation)

    Hello,
    I am using labview 2011 and need to latch the data from two timer tasks of a 6602 board at the same time and then perform the read. One task is a period measurement the other is a two edge speration.  It sounds pretty simple and I am sure it is, I just haven't located the correct information yet,  If someone would point point me in the correct direction.
    Thanks,
    Mike

    While it's true that a digital edge arm start trigger can help to sync the tasks to begin together, the nature of the measurements you're making also have a big impact on whether you can depend on the buffered data remaining "synced."   Both measurement types will latch measurement data at times determined by the signal(s) being characterized.  You cannot configure either task type to sample at a known constant rate.  You can only accept samples at the rate dictated by the signals' own edges.
    Ok, so having said all that, here are some implications:
    1. a cumulative sum of all your period data will effectively give you timestamps for all the active edges, with t=0 set by the arm start trigger edge.
    2. there is no information inherent in a two edge separation measurement that can identify the time relative to the arm start trigger.  You'll get a bunch of measured interval times with completely unknown times between those intervals
    3. caveat: if you are somehow using the same signal edge for both measurements AND getting one measurement of two-edge separation for each and every period measurement, ONLY then would you be able to reconstruct the timestamps relative to the arm start trigger edge.
    So I'd caution you that the idea of latching readings in sync or reconstructing relative edge times between the measurements is pretty unlikely to work except under some very specific circumstances.
    -Kevin P

  • How to synchronize two timer/counter tasks?

    Hi,
    I'm programming DAQmx through the nicaiu.dll with Matlab. I'm trying to start two different tasks, each controlling ctr0 and ctr1, respectively. Both timer/counter tasks should start on a common trigger, in my case /Dev/PFI0. Having searched the forum, I do understand that both tasks can't be triggered off PFI0. Instead, I probably need to trigger one of my tasks on a signal that turns on whenever the first task starts. My question is; What signal can inform my ctr1 task that my ctr0 has started? I basically want these two tasks synchronized, but not pulse by pulse since the pulse trains are quite different.
    Trying to trigger both off PFI0 results in a resource conflict. Triggering ctr1 on ctr0gate doesnt work either.
    Also, I need ctr1 to trigger on when the ctr0 tasks starts, i.e. not when the first ctr0 pulse appaers!
    Thanks,
    Per

    Thanks Ryan.
    I made some changes to my code now and it appears I CAN trigger both counters off PFIO (on an E-Series board). I only recently converted all my Traditional code into DAQmx, and got lost in my tracks. I was trying to generate finite pulse trains on both counters, and had used Finite timing on the counters to generate finite retriggerable pulse trains, without knowing that tied up the second counter. I solved this now using Pause Triggers instead. In the case where I generate single retriggerable pulses I still use a Start Trigger, and I can now Start BOTH counters using DAQmxCfgDigEdgeStartTrig and listening to PFIO with both counters (each counter running off a separate task).
    Sorry, I got things confused, and your solution isnt required anymore. Similarly to your solution, though, I have always used a (real) analog output routed externally to the PFI0 pin on my E-Series board as the synchronizing trigger. However, if I could avoid the external wiring it would be nice, so I will explore your solution a bit more
    I am not familiar with the concept of a 'dummy' task/channel. Can you point me to more documentation on this?
    I already use the analog inputs on this board from another app. Will creating a dummy AI tie up all analog inputs, so I can't then access my physical analog inputs from other applications (on the same board)?
     - Per

  • How to sync two time capsules?

    I have two time capsules on my network and want to set them to automatically sync files between them for redundancy.  How do I do this?

    In theory, you could have another application like Carbon Copy Cloner or SuperDuper backup Time Capsule 1 to Time Capsule 2, but the same risks apply.. I haven't tried this....and won't....but maybe another user has.
    Agree with Bob.. what you can do and what you should do are different. It is possible to use CCC and put the two TC in sync. The result will still be only as good as the quality of the first disk. That is a very slow way to backup.. TC is not designed as a NAS so it has no internal ability to sync files. It is purely designed as a target for Time Machine.
    If you do use CCC all packets are copied via the computer.. over the network.. so if you use wireless expect to never finish.. before the next TM backup starts and CCC will still be syncing.. ie you will have created an endless loop. Don't do it.

  • How to have two times the same iTunes library ?

    My parents are separated, so I have two computers (one with my father and the other one with my mother) and all my music is in the computer with my mother, I want to have the same iTunes library to my father how I should do?

    Not an easy one. Maybe you can try on both computers ) if they are both Macs or both PC to setup your iTunes Librery to be on an external USB drive. Under Windows make sure the USB HDD always mount with the same letter. Both computers should be Authorized for your account.

  • How to synchrorise two workflow tasks/calls?

    Hi all,
    We are writing a Workflow client application (in Java) and having problem getting valid state of the workflow because of the delay in PL/SQL API.
    Here's are two example:
    1) First we respond to a notification (using WF_Notification.Respond). After the Respond call has returned, we use a new transaction to scan the table for open notification for the user.
    We got back the responded notification as open notification as the table values have not been changed.
    We found that the table values will only change after a certain period.
    2) Expedite the process
    First we call the handleError API. Then read the table for activity statuses. Again, the table values are not updated even the handleError API has returned. We need to wait for 1 or 2 sec before the table are in valid states.
    Anyone know how can we synchorise these? May be there's a flag we can set to force the API blocks until it completed processing or a flag we can check to find out the status of the last API call.
    Thanks.

    I had similar issues when I developed a workflow portlet. I maintained a record of recently actioned notifications and hid them from the user for the next few requests.
    Regards,
    Mark

  • How to initiate two simultaneous tasks? First waits on second.

    I'm looking for guidance. I feel my problem is likely very common. It involves performing two tasks simultaneously.
    I have a digitizer (pxi5105) and a waveform generator (pxi5412). I need to generate a pulse and record the response simultaneously. My experiment basically works like this. Imagine that a hammer strikes an object causing it to vibrate. I need to record the resulting vibration beginning with the hammer strike. The generator is the hammer, it generates a pulse. The digitizer records the vibration.
    I can imagine a couple of ways to do this. One is to first initialize the digitizer (set it up to measure voltage), then start the generator. The rising generator signal would trigger the digitizer to take a reading. The reading would be returned to the program for processing.  I'm thinking the digitizer task would have to run in a separate thread. Upon completion, the digitizer task would invoke a callback function in the main program to process the data. I think there's an example program demonstrating this kind of threaded programming. Is this the best way?
    Another approach might be to first turn on the generator and let it run continuously. Then activate the digitizer to trigger off the generator signal as before. This would avoid the complexity of a separate thread. Is this a better approach?
    Is there a way to trigger generator and digitizer simulaneously?
    If there is documentation/example of this please point me there.
    Any recommendations are greatly appreciated.
    thanks!

    Hi,
    I do not think you have to use multiple threads.
    Being very expensive devices, the digitizer and the wave gen are capable of handling most of the stuff on their own.
    First, you configure the generator to generate and the digitizer to trigger and acquire.
    Then, you start the wave generation by software command (digitizer starts acquiring automatically after the waveform crosses the trigger level).
    Then, you wait for the acquisition to finish.
    Then, you read the samples from the digitizer into your array.
    Then, you process them.
    As you see the flow of operations that your program should implement are sequential, not parallel.
    So I do not see a point where you will need multiple threads.
    If the generated waveform is very slow and thus the acquisition is supposed to last too long,
    you can use a small timeout value for your "Fetch waveform" function and loop on it.
    This way, since you can process events within this loop, your program will keep being responsive.
    Hope this helps,
    S. Eren BALCI
    www.aselsan.com.tr

  • How to keep two Time Machine backups on to one drive without re-formatting

    i have two external drives drive 1 is 500gb and full with time machine backup, drive 2 is 1TB and has machine backup from jan2015 is it possible to combine the two into one?
    I run a mid 2011 iMac 21.5"

    No. Here is the most through information on Time Machine. http://pondini.org.
    Maybe something in there will give you other ides.

  • How to subtract two time?

    How to do TimeA-TimeB=TimeC?
    Solved!
    Go to Solution.
    Attachments:
    Time.jpg ‏44 KB

    I think NI need to improve subtract.
    lol!!!!
    Wait a minute. Are you seriuos?

  • How to add two time

    hi,
       My scenario is
       current date '20100920'  time is '054115'.
    i want to add 74 hours with this.
    i want output like  date '23100920'  time is '074115'.
    Thanks,
    Arun.
    Moderator message: date calculation questions = FAQ, please search before posting.
    locked by: Thomas Zloch on Sep 20, 2010 1:04 PM

    Hi,
    Use TO_NUMBER to convert those strings into numbers that you can add.
    Use TO_CHAR to convert that number back into a string.
    In PL/SQL:
    minutes := ( ( TO_NUMBER (SUBSTR (:psttime, 1, 2))
              + TO_NUMBER (SUBSTR (:pettime, 1, 2))
            * 60
            ) + TO_NUMBER (SUBSTR (:psttime, 4, 2)
              + TO_NUMBER (SUBSTR (:pettime, 4, 2);
    str := TO_CHAR (TRUNC (minutes / 60))
        || ':'
        || TO_CHAR ( MOD (minutes, 60)
                       , 'fm00'
                );In SQL, compute the NUMBER minutes in a sub-query, so you can use the alias in a super-query.
    This assumes that :psttime and :pettime are always well-formed: 2 digits for the hours, a colon, then 2 digits for the minutes. If you're not sure about the number of digits, the same basic approac will work, but the SUBSTRs will be a little more complicated.
    I hope this answers your question.
    If not, post a complete test script that people can run to re-create the problem and test their ideas. Include VARIABLE, CREATE TABLE, INSERT or whatever statements are necessary to provide some sample data, and also post the output you want from that sample data.

  • How to specify two time periods in data manager

    Hi
    How to configure a data manager where in I have to provide option of coping INR data from last year period to the current year.
    Note:- Users do not want to use copy package as we have to run logic for only few accounts
    Regards
    Edited by: Rohit26 on Sep 24, 2011 9:36 AM
    Edited by: Rohit26 on Sep 24, 2011 9:36 AM

    I think that PROMPT SELECTINPUT should be able to do what you need: have 2 selections of same Dimension in one Package. Take a look at example given in the documentation [http://help.sap.com/saphelp_bpc75_nw/helpdata/en/e9/23ece2cfd7489f8aa457d78d306a38/frameset.htm].
    Let us know if this is not what you are looking for.
    Gersh

  • How to VIEW two tracks's materials SIMULTANEOUSLY and SYNCHRONIZED in MONITORS?

    How to VIEW two tracks's materials SIMULTANEOUSLY and SYNCHRONIZED in MONITORS?
    "Program-monitor" shows the final edited material, and "Source-monitor" shows only one track at a time, and NOT SYNCHRONIZED with the sequence. "MultiCam-monitor" shows the tracks as I need, BUT editing is very stiff:  I want to do edits+cross-fades by hand IN THE TIMELEINE rather than by clicking the monitors. (Some of the "MultiCam-monitor's" other problems: 1) the timeline's time-inspector doesn't move while clicking the monitors, 2) vice-versa: monitor-image doesn't roll when the space-key is pressed for playback the timeline, 3) monitor doesn't show the cross-fades.....)   I understand the "Reference-monitor" doesn't help either at this.
    I would SO much like to SEE all tracks' materials simultaneously in whatever monitor, to edit efficently in the timeline.
    Software: Premiere CS3 version 3.2.0
    Operating System: Mac OS X (v10.4)

    You can only do this in the multicamera monitor.  That's what it's there for.  Proper procedure is to cut there, then go to the timeline and add transitions.
    If you're multicamera monitor playback isn't working correctly (I admit having a hard time understanding your points here), then try solving those.

  • FEBA - How to post two or more transactions at the same time?

    Hi,
        one of our banks sends the statemets with many lines that belongs to the same transaction. We have to post partially one line, and afterwards the other line. Any of you know how to post two lines at the same time from the bank statement?
    Thank you in advance,
    Miguel

    Hi,
    I'm sorry for replying so late.
    The solution I reached was to change the a few things in the standard.
    Now I have a new "context menu item". I select two or more transactions and I right-click the mouse. I select that "context menu item" and the next part of the code adds the total amount of the transactions to look for the correct post for the first transaction. Once posted automatically, the next transaction is posted automatically by the system.
    I hope you understand my English. I've problem with technical FI terms.
    Here you are the code:
    First I added a new contextual menu item:
    CL_FEBAN_ALV_GRID=============CCIMP
    call method e_object->add_function
        EXPORTING
            fcode = 'BS_POST_ITEMS'
            text = text-002.
    *{ INSERT DHTK904078 1
    *--> Miguel Estu00E9vez - 16/06/2008
    * RIPI 24/04/2008 - Conciliaciones
    * Permitir conciliar mu00E1s de un apunte a la vez
        call method e_object->add_function
            EXPORTING
                fcode = 'ZBS_POST_ITEMS'
                text = text-Z02.
    *<-- Miguel Estu00E9vez - 16/06/2008
    *} INSERT
        call method e_object->add_function
            EXPORTING
                fcode = 'BS_KILL_ADVICE'
                text = text-004.
    CL_FEBAN_ALV_GRID=============CCIMP
    when 'BS_POST_ITEMS'.
        call method cl_feban_propagator=>raise_event
            EXPORTING
                i_event = 'POST_ITEMS'
                i_ref_to_item = l_ref_to_item.
    *{ INSERT DHTK904078 2
    *--> Miguel Estu00E9vez - 16/06/2008
    * RIPI 24/04/2008 - Conciliaciones
    * Permitir conciliar mu00E1s de un apunte a la vez
        when 'ZBS_POST_ITEMS'.
            call method cl_feban_propagator=>raise_event
                EXPORTING
                    i_event = 'ZPOST_ITEMS'
                    i_ref_to_item = l_ref_to_item.
    *<-- Miguel Estu00E9vez - 16/06/2008
    *} INSERT
        when 'BS_LOCK_ITEMS'.
            call method cl_feban_propagator=>raise_event
                EXPORTING
                    i_event = 'LOCK_ITEMS'
                    i_ref_to_item = l_ref_to_item.
    CL_FEBAN_PROPAGATOR===========CM001
        when 'POST_ITEMS'.
            raise event post_items
                exporting i_ref_to_item = i_ref_to_item.
    *{ INSERT DHTK904078 1
    *--> Miguel Estu00E9vez - 16/06/2008
    * RIPI 24/04/2008 - Conciliaciones
    * Permitir conciliar mu00E1s de un apunte a la vez
        when 'ZPOST_ITEMS'.
            data: zvalor(1) value '' .
                export zvalor from 'X' to memory ID 'ZFEBA01'.
                raise event post_items
                    exporting i_ref_to_item = i_ref_to_item.
    *<-- Miguel Estu00E9vez - 16/06/2008
    *} INSERT
        when 'LOCK_ITEMS'.
            raise event lock_items
                exporting i_ref_to_item = i_ref_to_item.
    Now, I proceed to calculate the total amount of the selected transactions to look for the correct one to post.
    LNEW_FEBAF01
    *     user parameter
            l_feban_position type c.
            field-symbols: <items> type item_tab_type.
    *{ INSERT DHTK904077 1
    *--> Miguel Estu00E9vez - 16/06/2008
    * RIPI 24/04/2008 - Conciliaciones
    * Permitir conciliar mu00E1s de un apunte a la vez
        data: zvalor(1) value '',
            zkwbtr type kwbtr,
            kwb type kwbtr.
        import zvalor to zvalor from memory ID 'ZFEBA01'.
        if ( zvalor is not initial ).
            if not i_ref_to_item is initial.
                assign i_ref_to_item->* to <items>.
                loop at <items> into h_item.
                    select single kwbtr
                        into kwb
                        from febep
                        where kukey = h_item-kukey and
                            esnum = h_item-esnum.
                            zkwbtr = zkwbtr + kwb.
                endloop.
            endif.
            export zkwbtr from zkwbtr to memory ID 'ZKWBTR'.
        endif.
    *<-- Miguel Estu00E9vez - 16/06/2008
    *} INSERT
        refresh g_picked_items.
        if not i_ref_to_item is initial.
            assign i_ref_to_item->* to <items>.
            loop at <items> into h_item.
                move-corresponding h_item to h_picked_items.
                append h_picked_items to g_picked_items.
            endloop.
        endif.
        submit rfebbu00 and return
            user sy-uname
            with anwnd = r_doc->*-anwnd
            with s_kukey in s_kukey
            with s_esnum in s_esnum
            with buber = g_posting_area
            with mregel = '1'
            with function = 'C'
            with mode = g_mode
            with p_bupro = g_bupro.
    *{ INSERT DHTK904077 2
    *--> Miguel Estu00E9vez - 17/06/2008
    * RIPI 24/04/2008 - Conciliaciones
    * Permitir conciliar mu00E1s de un apunte a la vez
        if ( zkwbtr is not initial ).
            select single kwbtr
                into kwb
                from febep
                where kukey = h_kukey-low and
                    esnum = h_esnum-low.
                    zkwbtr = zkwbtr - kwb.
            export zkwbtr from zkwbtr to memory ID 'ZKWBTR'.
        endif.
    *<-- Miguel Estu00E9vez - 17/06/2008
    *} INSERT
        refresh s_kukey.
        refresh s_esnum.
        clear h_kukey.
        clear h_esnum.
    endloop. "loop over all picked items
    call function 'CUSTOMIZED_MESSAGE'
        EXPORTING
            i_arbgb = 'NEW_FEBA'
            i_dtype = '-'
            i_msgnr = '110'.
    RFEBBU00
    * original transaction currency provided and posting area = 2.
            ftclear-selvon = febep-fwbtr. "INSERT - mpEURO
        ENDIF. "INSERT - mpEURO
        CONDENSE ftclear-selvon NO-GAPS.
    *{ INSERT DHTK903977 1
    *--> Miguel Estu00E9vez - 16/06/2008
    * RIPI 24/04/2008 - Conciliaciones
    * Permitir conciliar mu00E1s de un apunte a la vez
        data: zkwbtr type kwbtr.
        import zkwbtr to zkwbtr from memory ID 'ZKWBTR'.
        if ( zkwbtr is not initial ).
            ftclear-selvon = zkwbtr.
            clear zkwbtr.
        endif.
    *<-- Miguel Estu00E9vez - 16/06/2008
    *} INSERT
    APPEND ftclear.
    ** Begin of comment C5053248
    * perform druck_buzei_ftclear using ftclear-agkon.

  • I have two time capsules (1TB, 2TB) and want to use one for another set of Macs (my Family). How do I set both up and keep all the Macs from joining both Time Capsules?

    I Have two Time Capsules (1TB and 2TB) and want to set one for business and the other for family - networking seperate Macs to each.

    Both should be plugged into the network with ethernet.. if at all possible.
    If you have a router already then both bridged otherwise one set to router and one to bridge.
    How do you access the TC? Ethernet or wireless?
    Are they located in the same area?
    You could set different wireless networks.. if they use wireless.. this is nice easy way to do it.
    You can set user account in the TC you want the business one to join with.. that will prevent access by the family.
    So there is a number of ways.. none are particularly secure btw.. the TC is a home not a business device.. if anybody wants access they press the reset for one second.. pofff all the passwords are default for 5min.. to allow people who forget their password to get access.
    On ML you can encrypt TM backups.. this is better for security if that is the problem.. and still use different user profile to prevent access.

  • How to select two things at the same time ?

    Hey guys, i'm French and I need your help !
    I'm working everyday on iWork and especially Pages.
    How to select two parts of a text at the same time ?
    Before we only need to select one, to press the "cmd" button and then to select another part. It doesn't work anymore!
    Thanks for you help
    and sorry for the mistakes !

    Hey guys, i'm French and I need your help !
    I'm working everyday on iWork and especially Pages.
    How to select two parts of a text at the same time ?
    Before we only need to select one, to press the "cmd" button and then to select another part. It doesn't work anymore!
    Thanks for you help
    and sorry for the mistakes !

Maybe you are looking for

  • Superimposing text on movie images

    The help guide says something about selecting the text file and then clicking on the "Options" button. There is not an "Options" button. I've also tried selecting the part of the movie onto which I want to overlay the text and then pasting it on. It

  • Display PDF Documents Stored In Database

    Hi I apologise that this question has been asked many times, but I just do not seem to be able to find answer to my question in many other posts over the years. We have pdf documents stored in database and wish for client to view from forms session.

  • Extended Classic Scenario

    Referring to note 963000, we are about to install SRM 5.0 as AddOn to Ecc ERP 2005. In SRM we would like to implement the "Exteded Classic Scenario", meaning the procurement process will take place locally in EBP and a copy of data is replicated to t

  • Where can I find "writing a Data Supplier" White Pages

    I am trying to write my own Function Module for CCMS. I read the following document from "https://cw.sdn.sap.com/cw/docs/DOC-17760". This documnet has the following line: The following overview documentation confines itself to passive data suppliers

  • FTP server: PORT command not supported??

    Hi, In a nutshell - we are trying to set up PASV -- PORT connection between a Tiger server (10.4.11) and another system (say it's a windows FTP server). Issuing a PORT command to a Tiger FTP server fails with this error: -> PORT 192,168,11,3,199,158