How to synchronize two timers that send data?

Hi, I have a problem:

I have a thread in which I have two timers with timerTask. two of them will send data on the server. the first 5 sec every one and the all other the 1 sec the problem is that when I run the defective computer application (disconnection with an IOException error) after 3-4 sec, I think it's probalby because in an instant, both of them are trying to send data and can only be in one second. I tried to create both a dataOutputStreams but this is not enough. Here is my code:

//in my thread, run method:

public void run(){

 synchronized(_firstTimer){

//send data every 5 sec
_firstTimer.scheduleAtFixedRate(new TimerTask(){

 public void run(){
   sendData(_data1);
}
},0, 5000);
}

while(true){

  synchronized(_secondTimer){

//send data every second
  _secondTimer.scheduleAtFixedRate(newTimerTask(){

        public void run(){

     sendData(_data2);
}

}, 0, 1000);
}

}//end of while

}//end of run()

//and sendData() method:

     public boolean sendData(byte[] _b){
            int length = _b.length;

            try{
                _os.write(_b, 0, length);
                _os.flush();

                return true;
            } catch(Exception e){   return false;   }

        }//end of sendData method

//where before in the code i've got:
SocketConnection _s = (SocketConnection)Connector.open(_address);
_os = _s.openDataOutputStream();

can someone please provide all my advice how to fix this?

Kind regards

a solution would be a 'executable queue", a vector that contains objects that implement the runnable interface and executes one by one.
the two timertasks add their treatment to the queue (synchronized) and directs the queue.

It is a lot of material on threads synchronization available on the net because it is one of the most basic problems of treatment / distributed computing.
I'm sure you can find detailed examples to sun.com and many other java sites.

Tags: BlackBerry Developers

Similar Questions

  • How to create the home group and how to connect two computers that are running windows 7. and also Remote Desktop connection!

    Someone help me how to create the home group and how to connect two computers that are running windows 7. and also Remote Desktop connection!
    step by step information!

    Hello

    I suggest you to refer to the links and check if it helps:

    Create a homegroup

    http://Windows.Microsoft.com/en-us/Windows7/create-a-HomeGroup

    Join a homegroup

    http://Windows.Microsoft.com/en-us/Windows7/join-a-HomeGroup

    Setting up a network home

    http://Windows.Microsoft.com/en-us/Windows7/setting-up-a-home-network

    Remote Desktop connection

    http://Windows.Microsoft.com/en-us/Windows7/products/features/Remote-Desktop-connection

    What types of connections remote desktop should I allow?

    http://Windows.Microsoft.com/en-us/Windows7/what-types-of-Remote-Desktop-connections-should-I-allow

    Remote Desktop connection: frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows7/Remote-Desktop-connection-frequently-asked-questions

    Let us know if it helps.

  • How can I use notifications to send data from different sources for the same chart?

    Hello

    I use the model of 'Continuous measurement and logging' project comes with LV 2013.

    It is extremenly helpful in understanding the messaging between the acquisition, graphic and loops of newspaper. (Thank you NEITHER!)

    I ran into a snag though.

    I want to change so that my graphic loop receives notifications of data from two sources of acquisition by the declarant.

    I have trouble getting the data from the two sources to display on one graph.

    I've isolated the problem in the attached vi.

    Here's what happens:

    1. I create 2 parallel loops data and send the data to a third parallel loop with the notifiers.

    2. the third loop receives data from one of the loops because one of the authors of just receiving notifications is to expire instead of receive data.

    Can anyone suggest how can I fix?

    Thank you.

    -Matt

    Here's my modification of your VI. I put notes on the block diagram to explain the changes. He uses a queue for data transfer to avoid data loss. It uses a notifier to stop loops. All local variables and value property nodes have been eliminated.

    The way loops are arrested probably let some data in the queue. No more of one or two iterations of each of the loops of data acquisition. If you need ensure that all data has been displayed (or recorded in a real application), then you must stop acquiring loop first and read the queue until you know it's empty and both other loops stopped. Then stop the render loop and release the queue and the notifier.

    Lynn

  • How to synchronize two chassis

    Dear all,

    I want to synchronize two chassis, chassis first has RFSG 5673E (S) and other chassis a DAMA (S) 5663E, they are connected via MXI, is there anyone who has this experience and can support me to apply it. I know that he used NI-Tclk to synchronize in a single chassis and there is another kit of tools for mult chasis, but I have no idea on how to use it!  Thanks in advance

    Best regards

    Al-Rawachy

    So I did a little research and to allow you to synchronize the two chassis together you must use a map of timing and synchronization in each frame so that you can share Tclk. This is for several reasons: first of all, as well as terminals IN CLK and CLK OUT, several PFI lines are required for the export of various signals used by T - CLK (i.e. Start, Stop and Sync triggers). In addition, the map of timing and synchronization is also necessary to replace clock background basket of 10 MHz, on the chassis of the slave with the master clock. It is essential for the two hunts reference the same clock synchronization. In addition, using a more stable clock source, as provided for in the calendar and map of synchronization, improve synchronization significantly.

    From there, a chassis are sync'd up, TCLKing la 5665 and 5673E should be simple enough. It should be simply a matter of configuration tasks the DAA and RFSG, with a single trigger configured, before feeding the two tasks of the TCLK vi. Here is an example for you to study what explains this:

    http://www.NI.com/example/30254/en/

    I hope this helps.

  • How to harvest two images that are overlapping?

    I was hoping someone can help me with this. I Googled it a little and tried different things, but cannot understand this. I don't even think that I have the correct terminology.

    I try to combine the two images. I have attached an image that illustrates what I'm tryng to do - I want to take a common stick figure and cultures so that part of it is hidden and looks like it is coming from a door or a hole. How I get there parts that are outside the door? I know this is probably very simple, but I just can't understand it!

    PORTAL.PNG

    Thanks for any help you can offer me.

    Mary

    Artificial intelligence you have to work with duplicates and slice things, that is to put the part of the dorframe which is originally under the figure, the upper part above and then use a copy of the top to cut the dark areas of the figure with Pathfinder operations or a clipping path.

    Mylenium

  • How to synchronize two ports data series at different frequencies of sampling?

    I have a .vi I'm reading two different sensors that operate at different sampling rates high.  I am able to read these two, however, there seems to be some problems of synchronization/strange offset with the devices.  The first device is a device running at 5 Hz GPS.  This is convenient because the time GPS is included in the data that I read.  The other device is a sensor operating at 6 Hz.  Ideally, I am recording the data of these two devices in the same file.  An example is attached.  It seems he collects GPS data, although it seems to write at much lower rates.  Strangely, as it is written to the file, it will slowly store 'blocks' of data in order to a much lower rate.  It seems that a lot of the GET of a buffer, and then it jumps ahead by about 5 seconds (see lines 214-220 of the attached file).  Meanwhile, the data from the sensor 6 Hz are get recorded normally.  I'm puzzled.  Would it not be better to connect these as separate sets of data in separate files?  Creating two executions of read/write "parallel" within the same .vi?

    Any help or examples, would be much appreciated!


  • How to select two channels and send to a series to write using the loop of the case

    I had a series write who have different orders to different situations. The same reading series should read both. How can I do it. Means that if I have a 500\r\nZ of the chain. I have a case, it should be - Zand 500\r\n other case + 500\r\n Z. But for boyh these cases must be read with a write serail. How can I do ITI. Help, please

    You can't guarantee that these two conditions would not be affected at the same time.  You will need to send a separate command for each condition.

    In addition, using EQUALS on floating points is dangerous.  You could never get the condition because a little really low could be turned off.

  • How to synchronize two cards NI9215 DAQmx?

    Hello

    I use two NI9215 DAQmx cards (analog inputs sample simultaneous 4ch) in a cDAQ-9174 chassis type.

    Because I need to acquire 8 channels at the same time, I have two NI9215 cards.

    My question is how to configure these cards to be synchronized?

    I use LabVIEW2009 SP1 dev Suite.

    Thanks for the replies!

    One of the nice things about CompactDAQ is that you can put multiple modules of the same time (analog, digital, etc.) in the same spot and they are automatically synchronized.  Then, to synchronize the two modules, create an analog input task and reference strings like "cDAQ1Mod1 / ai0:3, cDAQ1Mod2 / ai0:3.  It automatically synchronizes the two modules together.

  • How to synchronize two profiles in firefox, everything except localstore.rdf

    Yesterday, I asked about the binding cache between two profiles in firefox:

    https://support.Mozilla.org/en-us/questions/925836

    And I got to thinking. The only reason why I'm even a second profile is to have two 'places saved window' for purposes of multi-monitor. I want that these profiles to be EXACTLY the same except for the location in which they are open (which is registered in localstore.rdf). It occurred to me that with my current setup in the thread above, even if the caches are now linked... I still have to change twice bookmarks. Have two different stories, saved passwords, etc. A minor inconvenience at best, but it would still be nice to avoid.

    As I said, I want these identical profiles, except for the locations in which they are open. I know there are extensions for synchronization of profiles, but they all seem to be 1 star performance that hinder the mess. I prefer to do it manually, as I did with the cache. Possible?

    Found an answer myself, mklink. I delete the places.sqlite (the file where the bookmarks are saved) my 2nd monitor profile. I then go to CMD and create and MKLINK by running the following:

    MKLINK C:\Path\to\Mozilla\Firefox\Profiles\monitor2\places.sqlite C:\Path\to\Mozilla\Firefox\Profiles\default\places.sqlite

    This creates a shortcut in my profile monitor2, redirecting to the profile folder of the monitor of my first for the file places.sqlite. TADA, the bookmarks are sync'd and the changes are saved to both directions. I developed this and created mklinks for formhistory.sqlite, cookies.sqlite and permissions.sqlite. Works perfectly and synchronizes both ways, as did places.sqlite.

  • How does synchronization for files that are ' always available offline "?". (Explorer Windows, Windows 7, PC)

    I want to say is,

    Will be the synchronization process only pick up & roll down the changes that may have been made since the previous synchronization, or it will re - download all the contents of the file regardless of the fact that there are updates or not?

    Thank you

    Only files that have changed, it is a "delta".  Files that have not changed are ignored because there is no reason to download this data.

  • How to compare two different types of data

    I have two columns from two tables

    Suppose
    Select ced.incident_id in the cs_estimate_details Dec, question ra_customer_trx_lines_all where ratl.interface_attribute6 = ced.order_line_id and org_id = 101 and ced.incident_id = 22222;


    Here the error call 01722 - invalid number

    This is the scenario

    in fact the data type is not valid
    But even if I need to contact how can I do this.

    Published by: Sandy on June 24, 2010 05:46
    SQL> create table t1 as select level col from dual connect by level <= 10;
    
    Table created.
    
    SQL> create table t2 (col varchar2(2));
    
    Table created.
    
    SQL> insert into t2 select level col from dual connect by level <= 10;
    
    10 rows created.
    
    SQL> update t2 set col = 'A1' where col = 1;
    
    1 row updated.
    
    SQL> select * from t1, t2 where t1.col = t2.col;
    select * from t1, t2 where t1.col = t2.col
                                        *
    ERROR at line 1:
    ORA-01722: invalid number
    
    SQL> select * from t1, t2 where to_char(t1.col) = t2.col;
    
          COL CO
    --------- --
           10 10
            2 2
            3 3
            4 4
            5 5
            6 6
            7 7
            8 8
            9 9
    
    9 rows selected.
    
    SQL> 
    

    T1.Col = NUMBER
    T2.Col = VARCHAR2

    You can read these:

    http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:45012348053
    http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:11504677087008

  • How to make a loop that records data block without having to navigate to it

    I have a form with 2 tabs. Tab_1 displays the information of the monitor and tab_2 raw_data (that the user attempts to insert/update or delete) for the monitor. The two tabs have a button 'Post production', which messages the raw_data (in tab_2) to the database. If it is an update operation, I have to check if a column_value_1 has changed from what is present in the comic book. If so, then the user should be given a warning. The warning would be appropriate if the column_value_1 for any 1 record is changed. Therefore, the comparison can be stopped after first difference. The code in the when_button_pressed trigger looks like

    go_block (raw_data());
    first record;
    loop
    If value_changed then
    v_alert: = true;
    "exit";
    end if;
    IF: SYSTEM. LAST_RECORD = "TRUE" THEN
    EXIT;
    ON THE OTHER
    NEXT_RECORD;
    END IF;
    end loop;

    If v_alert then
    display_alert;
    end if;

    This should work fine if I'm in tab_2 (which displays the block of raw_data). But if I hit the 'Post production' button tab_1, go_block (raw_data()) would go to tab_2, I do not want to make. So, how can I browse the raw_Data in tab_2 block without having to navigate to this tab?

    Prosper,

    I don't have what it is possible to loop in a block without having to navigate to it. Instead, you can navigate to the control you are calling by GO_ITEM integrated.

    Kind regards

    Manu.

  • How can I make sure that no data "ghost" exists for a line on a data file?

    Even after committing the deletion of a row in a table, the data of "ghost" remains on the data file.

    'Ghost' data could potentially be accessed by a malicious user, circumvent the database access controls, using a hex editor on the data file.

    Short penetrating a tablespace again from the table (and all other segments) and then shredding the old data file, how to properly remove a specific line?

    Concerning

    Chris

    Transparent data encryption may be a solution for you, but which requires an additional license.

  • How to rasterize a chart that contains data from the path?

    In this function, when I type = 5 (create the path object), the object of trace appears on the canvas, but the BitmapData is empty. What I am doing wrong?

    public function createRandomObject (): Object

    {

    var MAXX:Number = 700;

    var MAXY: Number = 500;

    var MINRADIUS:Number = 20;

    var MAXRADIUS:Number = 100;

    var MAXHEIGHT:Number = 100;

    var MAXWIDTH:Number = 100;

    var MINHIEGHT:Number = 20;

    var MINWIDTH:Number = 20;

    var NUMTYPES:Number = 5;

    xPos var = Math.floor (Math.random () * MAXX);

    yPos var = Math.floor (Math.random () * MAXY);

    type var = Math.floor (Math.random () * NUMTYPES) + 1;

    var color: uint = Math.floor ((Math.Random () * 0xFFFF00) + 0x0000FF);

    graph: graph of var = new Graphic();

    graphic.graphics.beginFill (color);

    type = 5;

    var width: Number = Math.floor (Math.random () * (MAXWIDTH-MINWIDTH)) + MINWIDTH;

    var height: Number = Math.floor (Math.random () * (MAXHEIGHT-MINHIEGHT)) + MINHIEGHT;

    Switch (type)

    {

    case 1: //circle

    {

    var radius: Number = Math.floor ((Math.random () *(MAXRADIUS-MINRADIUS))) + MINRADIUS;

    width = height = radius * 2;

    graphic.graphics.drawCircle (RADIUS, RADIUS, RADIUS);

    break;

    }

    case 2: //square

    {

    height = width;

    graphic.graphics.drawRect (0,0, width, height);

    break;

    }

    box 3: //rect

    {

    graphic.graphics.drawRect (0,0, width, height);

    break;

    }

    box 4: / / ellipse

    {

    graphic.graphics.drawEllipse (0,0, width, height);

    break;

    }

    case 5: / / SVG path

    {

    var pathData:String = "M 0 L 0 40 0 40 40 40 0 L L Z;

    var pathData:String = « M 247 153 L 0 400 400 800 609 800 695 800 696 801 722 873 749 802 774 827 801 801 827 827 852 802 879 873 905 801 906 800 993 800 1201 800 1601 400 1201 0 801 400 400 0 247 153 Z » ;

    path: path of var = new Path();

    Path.Data = pathData;

    Path.x = 0;

    Path.y = 0;

    Path.Width = 200;

    Path.Height = 200;

    Path.Stroke = New SolidColorStroke();

    Path.Fill = New SolidColor (0xFFFFFF);

    Path.Winding = GraphicsPathWinding.EVEN_ODD;

    path.validateNow ();

    graphic.addElement (path);

    Graphic.Width = 200;

    Graphic.Height = 200;

    width = path.width;

    height = path.height;

    }

    }

    graphic.graphics.endFill ();

    var FillColor = 0xFF000000;

    mainCanvas.addElement (graphic);

    var bitMapData:BitmapData = new BitmapData (width, height, false);

    bitMapData.draw (graphic); It's empty when type = 5 (path data)

    Graphic.x = xPos;

    Graphic.y = yPos;

    var dataObject:Object = new Object();

    dataObject.bitMapData = bitMapData;

    dataObject.XPos = xPos;

    dataObject.YPos = yPos;

    dataObject.spriteName = graphic.name;

    Returns the dataObject object;

    }

    So I thought to it. Paths use BeforeDraw() and EndDraw(), making the filling operations and outline Draw(). The problem is that these functions not called until the path is rendered on the canvas. So, I expanded my class path and too rolled the EndDraw() function. In this function, I sent an event. Then, when I catch the event I can get the DisplayObject of the track (which is now filled) and pass this object in BitmapData().

  • How to call two variables that are to keep several value in loop for

    Hello

    I have 4 point, two list and two checkbox select. ID and class Section are select list and student id and the id of the object are check .i want to insert more id then a topic in the table corresponding to the student id then a plus.

    for example. When I select the IDs of class 1 and section A then student of class 1 and section has come into student card (checkbox element) and all the object corresponding to the class 1 comes in the object id (item checkbox).

    now I want to insert several selected for what is, multiple student topics in at table when I press submit Button.

    My table is

    CREATE TABLE 'STUDENT_SUBJECT_DETAIL '.
    (NUMBER OF 'S_NO',
    NUMBER OF "STUDENT_ID,"
    VARCHAR2 (50) "SUBJECT_ID",.
    "SESION' VARCHAR2 (50)
    )
    /


    I use this Code

    DECLARE
    STU wwv_flow_global.vc_arr2;
    VOID wwv_flow_global.vc_arr2;

    Start
    STU: = wwv_flow_utilities.string_to_table(:P57_STUDENT_ID);
    SUB: = wwv_flow_utilities.string_to_table(:P57_SUBJECT_ID);
    I'm looping 1.STU.count
    I'm looping 1.SUB.count
    insert into STUDENT_SUBJECT_DETAIL
    values (CLA_SUB_ID_SEQ.nextval, Stu (i), (i) Sub,: p57_SESION);
    end loop;
    end loop;
    END;

    Published by: Ed on November 20, 2009 22:10
    DECLARE
        STU wwv_flow_global.vc_arr2;
        SUB wwv_flow_global.vc_arr2;
    BEGIN
        STU:= wwv_flow_utilities.string_to_table(:P57_STUDENT_ID);
        SUB := wwv_flow_utilities.string_to_table(:P57_SUBJECT_ID);
        FOR i in 1..STU.count LOOP
            FOR i in 1..SUB.count LOOP
                insert into STUDENT_SUBJECT_DETAIL
                values(CLA_SUB_ID_SEQ.nextval,STU(i),SUB(i),:p57_SESION);
            end loop;
        end loop;
    END;
    

    None good for me:

    1. you have 2 loops, and they are both using the variable I as a counter.
    2. your insert must be in the form: insert into table (column names) values (to be inserted)
    3. why not use a trigger to get the nextval in the sequence?

    Trent

    Published by: tr3nton on November 21, 2009 16:16

Maybe you are looking for