Monitering Multiple Sockets in one thread

Hi all
i have a problem.....i want to create and moniter multiple sockets BUT Due to resourse problems i cannot create as many threads. I want to use multiple sockets in one thread.
Cani do something where i can have array of sockets and poll for data in a single while loop for all the sockets...OR u may suggest another solution for my porblem of using multiple sockets in one thread.
thanks in advance
Sai Burra

Here's a pseudocode solution I've used:
Create a thread to listen to incoming connections. Upon incoming connection, add the socket and inputstream to the incoming messages listener thread.
Create a threadpool for outgoing messages.
Create a thread to process incoming messages.
Incoming message listener thread:
Create a hashtable of sockets. Socket is the key, inputstream is the value.
Loop through each key, and assuming BufferedReader input you can poll by using (input.isReady()). If isReady() returns true, that means there is data on the stream coming in, so you'll need to process it.
After processing the data, call a thread from your outgoing messages threadpool to send the response - in case there is blocking, you'll still be able to process the rest of your data.
Sleep the incoming messages thread for 200 ms (300-400ms is quite adequate for real time processing I've found, at least the slowdown isn't noticable).
This should work for what you're talking about.

Similar Messages

  • Can i use multiple-Swfs in one page to implement the real multi-thread?

    When there are multiple .swfs  in one web page,  if there will be multiple instaces of flashPlayer and run in multiple thread ?-- Per Swf Per instance and Per thread, is it?

    hi,
       It will not work at all In web browser enviornment. If you considering to
    make a scheme in which u use two swfs one helper swf for background
    processing and another for Displaying Front End.Problem remains there if you
    manage to send data from your one swf to the other in same page using
    localConnection . When the processing starts in the helper swf whole page
    will going to be stucked for the period until the helper swf has done
    processing the data.So its no use at all. Altough this library can help you
    make time slice based threads http://code.google.com/p/async-threading/

  • Sharing socket object between threads - Is any sync required?

    For example, a thread receives (listens) datagram packets at incoming socket and forwards them downstream through another datagram socket. Another thread listens packets at this second socket and forwards the data via the first socket. It is possible that two threads invoke methods of the same socket (one is receiveng while another is sending). This situation is not described in the DatagramSocket manual. I beleive there is underlying synchronization at the OS kernel level. Can I relay on it? Thanks.

    I expected some critics for using old plain sockets instead of nio :)You should use NIO if you have hundreds of connections. If you have a small number of connections and want a simple implementation use blocking IO as you have.
    If you can have different
    threads reading or writing at once eg two readingor
    two writing then you need to use synchronisation.Shouldn't this be stated by the API designers somewhere?It is probibly covered in a tutorial or example somewhere.
    You have a different input and output stream. There is a lock on each. This is your best hint.
    Theoretically, nothing prohibits sending UDP packets in race conditions.
    In fact, this is what my program
    does - it respondes to different clients using one
    (server) datagram socket. The responses are produced
    by multiple threads. I suppose that java does not
    involve any state variables; thus, beleive that the
    system can accomplish the synchronisation unnecesary
    at the application level.That depends on how you build and send your messages. If each part of the message can be sent in one hit and the order does not matter you are fine.
    If you have a single object shared between threads, then all members are shared, not just static variables.

  • Advise on using DBMS_XA with multiple branches under one global transaction

    Dear all
    I need some advise on using DBMS_XA from PL/SQL with tightly coupled multiple branches under one global transaction. Basically, I've successfully written some PL/SQL code that in 3 different sessions attaches to 3 different branches of one global transaction and before ending each branch they can see each others uncommitted data. So far so good.
    However, I'm not sure I completely understand how each branch must call xa_end, xa_prepare and xa_commit correctly using two phase commit and my calls result in errors like:
    ORA-24767: transaction branch prepare returns read-only (XA error code 3 = Transaction was read-only and has been committed)
    ORA-24756: transaction does not exist (XA error code -4 = XID is not valid)
    ORA-02051: another session or branch in same transaction failed or finalized
    This is the structure of my programs (3 SQL*Plus sessions):
    main: Uses xid 123|0 (branch 0 of global transaction 123). This should be the coordinator that commits using two phase commit across the 3 branches
    m1.xa_start tmnoflags
    m2.DML
    m3.Wait for thread A + B to manually be started and run xa_end
    m4.xa_end tmsuccess
    m5.xa_prepare
    m6.xa_commit false
    thread A: Uses xid 123|A (branch A of global transaction 123)
    a1.xa_start tmnoflags
    a2.DML -- thread A can see main and thread B's data
    a3.xa_end tmsuccess
    a4.xa_prepare -- required?
    a5.Should we also call xa_commit false?
    thread B: Uses xid 123|B (branch B of global transaction 123)
    b1.xa_start tmnoflags
    b2.DML -- thread B can see main and thread A's data
    b3.xa_end tmsuccess
    b4.xa_prepare -- required?
    b5.Should we also call xa_commit false?
    The failing steps are:
    m5
    m6
    a4
    a5
    b4
    b5
    Before starting calling xa_end I see 3 rows in V$GLOBAL_TRANSACTION, eg (hex 7B = decimal 123):
    FORMATID GLOBALID BRANCHID BRANCHES REFCOUNT PREPARECOUNT STATE FLAGS COUPLING
    203348753 0000007B 00000000000000000000000000000000 3 3 0 ACTIVE 0 TIGHTLY COUPLED
    203348753 0000007B 0000000000000000000000000000000A 3 3 0 ACTIVE 0 TIGHTLY COUPLED
    203348753 0000007B 0000000000000000000000000000000B 3 3 0 ACTIVE 0 TIGHTLY COUPLED
    Thanks a lot in advance.
    Cheers
    Finn

    OK, I've figured it out. This is poorly documented as it's not well explained how to handle the various return codes. Turns out that all but the last xa_prepare calls return dbms_xa.xa_rdonly (tightly coupled branches are combined -- "read only" optimization), the last one returns dbms_xa.xa_ok and this is when you should call xa_commit.
    Now my next problem is that DBMS_XA doesn't work from within jobs (DBMS_JOB and DBMS_SCHEDULER), which makes it very difficult to use DBMS_XA. My purpose of using DBMS_XA is to coordinate work across multiple sessions in one transaction but if I can't easily create the multiple sessions, I'm stuck.
    When called from a job, xa_start throws:
    ORA-24789: start not allowed in recursive call
    on Oracle 11.2. In Oracle 11.1 it works, but xa_end fails with
    ORA-25352: no current transaction
    so I guess in fact the xa_start call didn't really work either, even though it returned tm_ok.
    I'm now trying to find a workaround on how to use DBMS_XA from within jobs, please comment if you have any suggestions. Or if you have any suggestions on other means of establishing the concurrent sessions (I wouldn't like to resort to external programs that need username/password to connect as password management would be a security issue).
    Thanks in advance.
    Cheers
    Finn

  • Multiple databases in one file: a small snafu

    Hello everyone,
    Opening multiple databases in a single file is an administrative convenience. It is well explained in the manual (see db/docs/ref/am/opensub.html). Normally, there is little difference between databases in their own physical files or grouped together in a single physical file. There is one small sentence in the manual that says the following:
    (begin fragment)
    However, since multiple databases in a file exist in a single physical file, opening two databases in the same file simultaneously requires locking be enabled unless all of the handles are read-only. As the locks for the two databases can only conflict during page allocation, this additional locking is unlikely to affect performance.
    (end fragment).
    I didn't pay attention to it, except the "unlikely to affect performance" part which told me that I wasn't to worry about it. The sun was shining. Life was good.
    And I was wrong. It was one of those "epic bug quests" I had to embark on, only to realise that it may not be a BDB bug, but my carelessnes. Nevertheless, I'm left with an uneasy feeling which I would like to explain here.
    Consider BDB configured as a concurrent data store.
    There are 2 threads. The first thread has the following pseudocode:
    cursor1 = db1->cursor(...)
    while(cursor1->c_get(... DB_NEXT...))
    // 1
    cursor2 = db2->cursor(...)
    while(cursor2->c_get(... DB_NEXT...))
    The second thread does only the following:
    db3->put(...)
    db1, db2 and db3 are all distinct databases. All cursors are read-only (the cursor implicitly used in db3->put is of course a write cursor).
    While the first thread is running, the second thread executes db3->put(...) at "//1".
    Question: what happens?
    Answer 1: if db1, db2 and db3 reside in different physical files, nothing special happens. Everything proceeds as it should.
    Answer 2: if db1, db2 and db3 reside in the same physical file, both threads block "sometimes".
    The "sometimes" used here means "when the put operation in thread 2 needs to allocate a new page".
    Reading the BDB source code is extraordinarily difficult (which says more about my limitations than about the clarity of the code) but here is what happens, as far as I could determine:
    (thread 1) cursor1 needs and acquires a read lock on db1
    (thread 2) db3->put needs a write lock on db2 to allocate a new page. Since db2 is in the same physical file as db1 and thread 1 already has a read lock, thread 2 waits until the read lock is released. Thread 2 blocks.
    (thread 1) cursor 2 needs a read lock on db3. For some reason, BDB detects that the another thread is waiting for a write lock on the physical file, and thread 1 blocks.
    Both threads block waiting on each other to complete.
    I suppose the system is the way it is to avoid starvation, but there you have it: be careful when you're lumping together multiple databases in one file!
    Anyone who can clarify or confirm this is welcome.
    Vincent

    I had experienced a similar problem. I run multiple process. Each one of them starts a transaction that does db->put and db->pget to its own database (which also has a secondary index). When each database is in a separate physical file there is no problem but when I put all databases in a single file the processes start to dead-lock.
    The following combination of options solved the deadlocking problem:
    - use serializable isolation level instead of snapshot, i.e. do not pass DB_TXN_SNAPSHOT to txn_begin
    - do not pass the DB_NO_WAIT option to txn_begin
    - use Btree instead of a Hash
    Hope that helps.

  • ITunes library synchronization across multiple users on one computer

    I've got a PC running MS XP/Home, with a separate user account for each family member. I also repointed all the iTunes library file pointers to the SAME file on the "D" hard drive (taking all that pressure off the "C" drive, which is filling up!)--so each iTunes incarnation for each user points to the same (master) file.
    But when I download music from the Music Store into the library from my user account, it doesn't show up in the iTunes library listing when my daughter logs in using her account--and she can't download it to her iPod.
    Why? I bought it for her; why should she have to download it? It's all on one computer!
    Is it that iTunes really can't handle multiple users on one computer??????? I don't get it...this isn't any copyright or license issue.
    I'd appreciate any tips to get the iTunes on one user's account to "restudy" the library to see if it's been changed by another user. We're all one family on our one computer!
    --DaveTh
    VAIO   Windows XP  
    VAIO   Windows XP  

    See this thread for answers: http://discussions.apple.com/message.jspa?messageID=1285867#1285867
    Post back here with questions if you have any.

  • Is it possible to combine multiple Pur Reqs for multiple materials to one vendor into one PO through MD07?

    We have material planners who use MD07 (traffic signal screen) Stock/Requirements List, Collective Access tab to review material requirements by MRP Controller.  Once the list is created, they select individual materials and review them in MD04.  In a lot of cases, Purchase Reqs (PRs) are reviewed and adopted into POs individually for each material.  Sometimes they will combine multiple PRs for one material into one PO.  This is a good practice.  However, from what I have found, it is not possible to combine multiple PRs for multiple materials into one PO.  If this was done it would dramatically reduce the number of POs that we are issuing to suppliers.  Problem statement:  We issue too many POs which causes additional influxes down the line (receiving dock/goods receipts processing, receiving issues, invoices, invoice issues, etc.).  Does anyone know of a way to address this problem without a major overhaul in approach or customization of the system?  Thank you in advance!   

    Hello Michael
    As far as I know, this is not possible directly from MD07, only from the MM transactions.
    The following thread suggests the following procedure to convert several PRs into one PO:
    Conversion of multiple PR into single P.O
    Drag and drop the first PR from the item overview to the shopping card on top of ME21N,
    then open the PO detail delivery schedule tab and drag  and drop all other PR to the shopping card shown  in the schedule tab
    You can use the same procedure, calling the order conversion from MD07 and then drag and drop another PRs into this PO.
    BR
    Caetano

  • Multiple Values For one Condition in Choose From List

    I have used one Business Partner Choose From List in my form but i want to give condition in that choose from list on GroupCode .But the condition will have multiple values like 100,102,104 then how i will write the code to incorporate multiple values for one single condition.

    Hi,
    Check this thread
    How to set a Multiple condition in a single CFL
    Hope that helps,
    Vasu Natari.

  • Why has mail on the ipad grouped several emails from different people with different subject matter into one thread?

    This is really annoying.
    The email initially started with me sending to one person. Which we then conversed several times without any issues.
    I then sent a separate email completely unrelated to someone on a completely different email address, but when they replied back somehow their reply joined the same thread as this other email i sent initially.
    Thinking that it might be a one of... I ignored it.
    However, just now, an email i created through the LinkedIn app, which i sent from LinkedIn to a contact, somehow joined that first thread, when the person on linked in replied back to me.
    Obviously i receive an email to my Mail account whenever someone messages me on linked in... But why on earth would that reply automatically get grouped into the completely different thread of emails?
    I NOW have emails to three different people who are completely unrelated with three completely unrelated subjects, that are appearing in one thread with no obvious way to separate these.
    Any solutions or suggestions? I've tried to move them, but it will only let me move the the messages into different folders, and not my inbox as separate messages.

    Hi Anya!
    Thanks for the response. Regarding your question, Yes, I have confirmed that people were receiving multiple copies.
    I've confirmed this as I had left a Gmail message open on my browser window and opened that same message from Mail: As I was writing the response from Mail, without sending anything, new notifications started to appear over the same message in the browser window, notifying me there were new messages from Myself! So when I started to open those "new replies", I came to the conclusion that as I was typing, a draft was being saved and sent as a new message at the same time, therefore sending a lot of emails until I finished to write the message without knowing...
    Hard to explain but hope I've made my point.
    Thanks!
    D

  • NIO issue - writing to sockets from 2 threads

    Hi All,
    I have some questions regarding a NIO-server i'm developing. I have read many posts relating this issue, but still...
    I have one thread that does the Selector.select() and read & write to the sockets
    I have another thread that uses the same Selector and changes the interestOp to OP_WRITE (then wakes up the Selector).
    I have a Connection (attachment) that i use to hold the inputBuffer and outputBuffer to handle remainings.
    I've read a post in which some ppl wrote the stages of using th OP_WRITE and it was suggested that only when i wanna write i'll add the OP_WRITE and exclude it in the isWritable() - so i'm doing that.
    My questions are:
    1. Is it safe to change the interestOp on a key from another thread?
    2. What happens if the select() is in process?
    3. Are there any other problems with my implementation?
    4. What other way i have to write to a socket from 2 different threads (withough putting a lock on the socket)?
    Thanks.

    Reset your thinking a bit. You should only register for OP_WRITE when you have just executed a 'short write', i.e. a return value > 0 but < the length you asked to write, and you should deregister OP_WRITE any time you execute a 'complete write', i.e. a write which writes everything you asked for. At all other times you should just write and handle your own syncrhonization. The reason is that socket channels are almost always writable except under the condition described so you will just be returning early from select() for nothing.

  • Change duration of multiple clips "as one" overall clip?

    Here's my situation:
    I have a song at 127 BPM. I have a music video (muted sound) at 125 BPM.
    I've spent a long time slicing up clips from the video into different channels and muliple clips to form one timeline (but with many clips and channels lined up).
    I now want to change the overall duration of the video clip to match the BPM of the song (which I should have done in the first place), but the video is, as previously stated, sliced up in mulitple clips in multiple channels. How can I change the duration of all clips at one time, where the end and start of the clips still line up to eachother?
    This would've been incredibly easy if there were a un-nesting feature. Where I can nest multiple clips, change the duration, and un-nest the clips to slices clips with a changed overall duration. (Which is not possible. Yes, I can drag the clips out of the nested clip, but the clips will still have the original duration).
    TL;DR: How can I change duration of multiple clips "as one" overall clip?

    Never mind. I've found a alternate solution. I used a time stretch calculator at http://mp3.deepsound.net/eng/samples_calculs.php and time stretched all the clips to match the BPM of the song. Now I only need to snap all the clips, which can be done one by one, but I found this trick to snap all the clips at once: http://vimeo.com/27428526.
    I'll just let this thread stay open so other with the same problem can find this

  • Multiples RPD in one server

    Hi, I am try configured two rpd(paint and samplesales) in one server, I have one presentation services (analytics) up in the port 9710 and I want startup the second instance of presetation whit the command:
    fmw@server2:~/BIEE/OracleBI/setup> ./sawserver.sh -c /weblogic/BIEE/OracleBIData/web/config/instanceconfigsales.xml
    Type: Information
    Severity: 30
    Time: Mon Apr 26 11:56:31 2010
    File: project/sawserver/sawserver.cpp Line: 386
    Properties: ThreadID-4113512640
    Location:
    saw.sawserver
    Oracle BI Presentation Services 10.1.3.4.1 (Build 090414.1900) are starting up.
    Type: Warning
    Severity: 40
    Time: Mon Apr 26 11:56:32 2010
    File: project/webcomm/socketrpcserver.cpp Line: 323
    Properties: ThreadID-4113512640
    Location:
    saw.rpc.server.initialize
    saw.sawserver
    Port 9710 was reported as currently in use by the system. The configured listener address may be in the TIME_WAIT state or may be in use by some other service.
    Type: Error
    Severity: 20
    Time: Mon Apr 26 11:56:33 2010
    File: project/sawserver/main.cpp Line: 338
    Properties: ThreadID-4113512640
    Location:
    saw.sawserver
    Port 9710 is in use on the local system. [Socket:12]
    and this is my instanceconfigsales.xml where I specified the use of the port "9711" not 9710, then Why he try startup for the port 9710, I miss any configuration, How I can fix this???
    <?xml version="1.0" encoding="utf-8"?>
    <WebConfig>
    <ServerInstance>
    <Listener port="9711"/>
    <DSN>AnalyticsWebSampleSales</DSN>
    <CatalogPath>/weblogic/OracleBIData/web/catalog/samplesales</CatalogPath>
    Thanks any help

    Hi,
    You have to change to <Listener port="9711"/> to <Listener port="9712"/>
    Refere the below forum articles.
    Multiple RPD & Multiple Presentation service instance on single BI Server
    And See the below links are helpful for you.
    1.http://debaatobiee.wordpress.com/2009/10/01/multiple-rpd-multiple-presentation-service-instance-on-single-bi-server/
    2.http://rnm1978.wordpress.com/2009/08/25/multiple-rpds-on-one-server-part-1-the-bi-server/
    3.http://rnm1978.wordpress.com/2009/08/25/multiple-rpds-on-one-server-part-2-presentation-services/
    Award points if its helpful for you.
    Thanks,
    Balaa...

  • Printing multiple photos onto one page

    Sorry, fairly new to PSE9!
    Have a group of photos I need to print to actual size (3cm x 4cm) to go into a photo frame.  They are all cropped and ready to go but there doesn't seem to be an option to print multiple images onto one page at a custom size?  A contact sheet only gives me the option for the number of columns and picture package doesn't give any such option either as far as I can see!  I'm sure I must be missing something here!
    Any help much appreciated!  Don't want to waste photo paper printing each small photo individually!

    http://www.elementsvillage.com/forums/showthread.php?p=206785#post206785
    Post #6 in this thread provides standard directions.

  • Multiple Sockets on Palm

    Hi, I'm working on a Palm application in a Palm Emulator connected to a SocketServer. I'm accessing SQL Server DB to retrieve items to put on my combobox. Now that I retrieved the items, I need to send them to the Palm application. Previously, I concat the items into one string, send them to the Output Stream using the write() method. Then I realised that J2ME CLDC does not support StringTokenizer which I used to process any string from the palm to the server.
    So now I've stored the combobox items into a Vector and I want to send the elements one at a time through many sockets. So my question is how does a Server send multiple sockets?
    Please keep in mind that I am using J2ME CLDC and all J2ME socket examples I've seen only shows one socket and only one file being sent and received.
    Please reply, thanks.
    zad.

    I think you should try making your own stringtokenizer instead.

  • Multiple delivery into One invoice

    Dear All
    Issue regarding multiple delivery into one invoice
    1 When i am creating multiple delivery doc into one invoice, its possible for domestic[local sales] but when i am creating multiple delivery doc into one invoice for export it is not possible.
    I have checked with the threads and tried it out with copy control with VBRK/VBRP [001/003/004]
    Is there any specific customization for exports?
    Regards
    Sandeep Bhowmick

    Dear Lakshmipati
    As per your instruction i have done the split analysis:
    split analysis:
    Split due to different header data
    Field Name                           :$00000001           $00000002
    Number of foreign trade data      : 0000000266         0000000267
    The invoice is generating against one delv document, it could not be combined. In copy control any changes i have to make
    Regards
    Sandeep Bhowmick
    Edited by: Sandeep Bhowmick on Jan 17, 2009 7:33 AM
    Edited by: Sandeep Bhowmick on Jan 17, 2009 7:34 AM

Maybe you are looking for