I need help with socket connection pooling please

I need a basic connection pooling system for the code below users sets number connections 5 etc.
<main class>
s = new ListService(ssock.accept(),serverDir); //give list to client
Thread t = new Thread(s);
t.start();
<main class>
class ListService implements Runnable
Socket client;
String serverDir;
public ListService(Socket client,String serverDir)
this.client = client;
this.serverDir = serverDir;
public void run()
try
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
// send something to client
catch(Exception e)
System.out.println(e);
System.out.println("client disconnected\n");
catch(Exception e){}
Thank you so much

My code already accepts multi clients I need pooling only 5 clients can be using the server at a time when one client disconnects that means another incoming client can enter the pool to use the server.
I tried to do a counter so when a connection is made it increments and then if counter>=numOfClients
set a variable to true or false and this is sent with the server setup so it determines if the server code is run or it just closes the connection but there is no way I can access the counter variable from within a runnable class thread when a client closes connection it should -1 from the variable
thanks

Similar Messages

  • Need help with threads?.. please check my approach!!

    Hello frnds,
    I am trying to write a program.. who monitors my external tool.. please check my way of doing it.. as whenever i write programs having thread.. i end up goosy.. :(
    first let me tell.. what I want from program.. I have to start an external tool.. on separate thread.. (as it takes some time).. then it takes some arguments(3 arguments).. from file.. so i read the file.. and have to run tool.. continously.. until there are arguments left.. in file.. or.. user has stopped it by pressing STOP button..
    I have to put a marker in file too.. so that.. if program started again.. file is read from marker postion.. !!
    Hope I make clear.. what am trying to do!!
    My approach is like..
    1. Have two buttons.. START and STOP on Frame..
    START--> pressed
    2. check marker("$" sign.. placed in beginning of file during start).. on file..
         read File from marker.. got 3 arg.. pass it to tool.. and run it.. (on separate thread).. put marker.. (for next reading)
         Step 2.. continously..
    3. STOP--> pressed
         until last thread.. stops.. keep running the tool.. and when last thread stops.. stop reading any more arguments..
    Question is:
    1. Should i read file again and again.. ?.. or read it once after "$" sign.. store data in array.. and once stopped pressed.. read file again.. and put marker ("$" sign) at last read line..
    2. how should i know when my thread has stopped.. so I start tool again??.. am totally confused.. !!
    please modify my approach.. if u find anything odd..
    Thanks a lot in advance
    gervini

    Hello,
    I have no experience with threads or with having more than run "program" in a single java file. All my java files have the same structure. This master.java looks something like this:
    ---master.java---------------------------------------------------
    import java.sql.*;
    import...
    public class Master {
    public static void main(String args []) throws SQLException, IOException {
    //create connection pool here
    while (true) { // start loop here (each loop takes about five minutes)
    // set values of variables
    // select a slave process to run (from a list of slave programs)
    execute selected slave program
    // check for loop exit value
    } // end while loop
    System.out.println("Program Complete");
    } catch (Exception e) {
    System.out.println("Error: " + e);
    } finally {
    if (rSet1 != null)
    try { rSet1.close(); } catch( SQLException ignore ) { /* ignored */ }
    connection.close();
    -------end master.java--------------------------------------------------------
    This master.java program will run continuously for days or weeks, each time through the loop starting another slave process which runs for five minutes to up to an hour, which means there may be ten to twenty of these slave processes running simultaneously.
    I believe threads is the best way to do this, but I don't know where to locate these slave programs: either inside the master.java program or separate slave.java files? I will need help with either method.
    Your help is greatly appreciated. Thank you.
    Logan

  • Need help with flash player installation please !!!!

    Hello,
    I need help with my flash player installation because every time I access a movie this is the message I receive. 
    This content on Xfinity TV is not available for viewing with Chrome's "Incognito" mode. To play this video using Chrome, please view this page without "Incognito" mode.
    Still having problems? Try resetting your Flash player license.

    Incognito mode is a Google Chrome setting when you open a new window (Cmd+Shift+N on a Mac Ctrl+Shift+N on Windows) It opens a "private" window with no cookies and no tracking. The problem with it is that when you disable cookies, your license files are not sent to the site (whetehr it's YouTube or xFinity or any other that uses license files for paid content)  and it treats you as if you're a first time visitor. Paid videos won't play wihtout the cookies sending the license file info.
    This isn't a Flash Player setting. It's in Chrome. I did some research and according to Google, "Incignito" mode is off by default, and can ONLY be activate by the keyboard shortcut. There IS a way to disable it from the registry http://dev.chromium.org/administrators/policy-list-3#IncognitoModeAvailability

  • I need help with printing labels.  please

    I need help with printing labels.  thanks in advance

    Welcome to Apple Support Communities.
    In Address Book, first select a name or group of names to print.
    Then File, Print, select Style, Mailing Labels, then Layout to select a specific target label (such as an Avery number), or define your own...

  • Need help with sockets!

    I am fairly new to network programming. All help is very appreciated!
    I know how to work with sockets and serversockets, and how to transmit data between the host and the clients. My problem is that I have no idea how to get my working program to work online.
    -It works fine when I have both the client and host programs running on my computer.
    -It works fine when I have the host on one computer (192.168.1.103), and the client running on another one (192.168.1.102 I think). I guess in this case I'm just using the linksys network, not the internet.
    -IT DOES NOT WORK WHEN I upload the files to my website, and run them from there. I am not sure what the cause is; the host correctly creates the serversocket and waits, but never receives a connection to the client. The client seems to connect; it does not throw any exceptions, and creates a socket, but never actually communicates with the host.
    Could the problem be with my applets' permissions?
    What hostname/IP should I have the client connect to? It is on the same server, so would localhost work, or do I need to connect to my websites ip, or to the hostname?
    What other problems could there be?!?!?!?!
    Thank you so much for your help!!!!!!!!!!

    Donv7 wrote:
    1) Is the server program running on the same machine as the webserver?
    2) How are you opening this Socket in the applet? You mentioned something about localhost, that would be wrong. You should use the www hostname. Same as the host that served the HTML that the applet lives in.1- My server program and client program are actually the same thing. This doesn't sound too good.
    And applet is not a suitable endpoint for a P2P application. An applet is going to be a client. Not a server.
    Are you actually running a server (of your program) on the webserver? Or are you hoping that two applets will talk to each other with one acting as a server? Because that's not going to work.

  • Need Help with Migration...Please

    Hello,
    I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my questions:
    1.  As I am not replacing the iMac, but rather adding a MacBook Pro to the mix, should I migrate the software, settings, files, etc. from the iMac to the MacBook?  Is there an issue running computers which are clones in the same environment?  Is it a bad idea to migrate?
    2.  Assuming # 1 is okay to migrate, what is the best way?  Is it best directly from the iMac or from the Time Capsule?  I do have a Thunderbolt to Ethernet adapter on hand. 
    3.  Is there a link that would help me navigate the migration?
    4.  How long should the migration in #2 take?
    5.  Will I need to change any settings on the iMac, iPhone, or iPad afterwards?
    6.  Will my contacts and calendar sync with iCloud automatically, or do I have to change a setting on the MacBook to make that happen?
    7.  Also, as I'm leaving town tomorrow and want to take the MacBook Pro with me and I'm unsure I've the time to Migrate and tweak, can I jus turn on the MacBook (still not turned on), use it as it is, and then migrate when I get back home?
    Any help would greatly be appreciated.  Thank you!

    Hello,
    I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my questions:
    1.  As I am not replacing the iMac, but rather adding a MacBook Pro to the mix, should I migrate the software, settings, files, etc. from the iMac to the MacBook?  Is there an issue running computers which are clones in the same environment?  Is it a bad idea to migrate?
    2.  Assuming # 1 is okay to migrate, what is the best way?  Is it best directly from the iMac or from the Time Capsule?  I do have a Thunderbolt to Ethernet adapter on hand. 
    3.  Is there a link that would help me navigate the migration?
    4.  How long should the migration in #2 take?
    5.  Will I need to change any settings on the iMac, iPhone, or iPad afterwards?
    6.  Will my contacts and calendar sync with iCloud automatically, or do I have to change a setting on the MacBook to make that happen?
    7.  Also, as I'm leaving town tomorrow and want to take the MacBook Pro with me and I'm unsure I've the time to Migrate and tweak, can I jus turn on the MacBook (still not turned on), use it as it is, and then migrate when I get back home?
    Any help would greatly be appreciated.  Thank you!

  • [8i] Need help with hierarchical (connect by) query

    First, I'm working in 8i.
    My problem is, I keep getting the error ORA-01437: cannot have join with CONNECT BY.
    And, the reason I get that error is because one of the criteria I need to use to prune some branches with is in another table... Is there anyway to work around this? I tried an in-line view (but got the same error). I thought about using the connect by query as an in-line view and filtering off what I don't want that way, but I'm not sure how to filter out an entire branch...
    Here is some simplified sample data:
    CREATE TABLE     bom_test
    (     parent          CHAR(25)
    ,     component     CHAR(25)
    ,     qty_per          NUMBER(9,5)
    INSERT INTO     bom_test
    VALUES     ('ABC-1','101-34',10);
    INSERT INTO     bom_test
    VALUES     ('ABC-1','A-109-347',2);
    INSERT INTO     bom_test
    VALUES     ('ABC-1','ABC-100G',1);
    INSERT INTO     bom_test
    VALUES     ('ABC-1','1A247G01',2);
    INSERT INTO     bom_test
    VALUES     ('ABC-100G','70052',18);
    INSERT INTO     bom_test
    VALUES     ('ABC-100G','M9532-278',5);
    INSERT INTO     bom_test
    VALUES     ('1A247G01','X525-101',2);
    INSERT INTO     bom_test
    VALUES     ('1A247G01','1062-324',2);
    INSERT INTO     bom_test
    VALUES     ('X525-101','R245-9010',2);
    CREATE TABLE     part_test
    (     part_nbr     CHAR(25)
    ,     part_type     CHAR(1)
    INSERT INTO     part_test
    VALUES     ('ABC-1','M');
    INSERT INTO     part_test
    VALUES     ('101-34','P');
    INSERT INTO     part_test
    VALUES     ('A-109-347','P');
    INSERT INTO     part_test
    VALUES     ('ABC-100G','M');
    INSERT INTO     part_test
    VALUES     ('1A247G01','P');
    INSERT INTO     part_test
    VALUES     ('70052','P');
    INSERT INTO     part_test
    VALUES     ('M9532-278','P');
    INSERT INTO     part_test
    VALUES     ('X525-101','M');
    INSERT INTO     part_test
    VALUES     ('1062-324','P');
    INSERT INTO     part_test
    VALUES     ('R245-9010','P');This is the basic query (with no pruning of branches):
    SELECT     LEVEL
    ,     b.component
    ,     b.parent
    ,     b.qty_per
    FROM     bom_test b
    START WITH          b.parent     = 'ABC-1'
    CONNECT BY PRIOR     b.component     = b.parentThe query above gives the results:
          LEVEL COMPONENT                 PARENT                        QTY_PER
          1.000 101-34                    ABC-1                          10.000
          1.000 A-109-347                 ABC-1                           2.000
          1.000 ABC-100G                  ABC-1                           1.000
          2.000 70052                     ABC-100G                       18.000
          2.000 M9532-278                 ABC-100G                        5.000
          1.000 1A247G01                  ABC-1                           2.000
          2.000 X525-101                  1A247G01                        2.000
          3.000 R245-9010                 X525-101                        2.000
          2.000 1062-324                  1A247G01                        2.000
    9 rows selected....but I only want the branches (children, grandchildren, etc.) of part type 'M'.
    e.g.:
          LEVEL COMPONENT                 PARENT                        QTY_PER
          1.000 101-34                    ABC-1                          10.000
          1.000 A-109-347                 ABC-1                           2.000
          1.000 ABC-100G                  ABC-1                           1.000
          2.000 70052                     ABC-100G                       18.000
          2.000 M9532-278                 ABC-100G                        5.000
          1.000 1A247G01                  ABC-1                           2.000Any suggestions?

    Hi,
    user11033437 wrote:
    First, I'm working in 8i.
    My problem is, I keep getting the error ORA-01437: cannot have join with CONNECT BY.
    And, the reason I get that error is because one of the criteria I need to use to prune some branches with is in another table... Is there anyway to work around this? I tried an in-line view (but got the same error). Post your query. It's very hard to tell what you're doing wrong if we don't know what you're doing.
    ...but I only want the branches (children, grandchildren, etc.) of part type 'M'.
    e.g.:
    LEVEL COMPONENT                 PARENT                        QTY_PER
    1.000 101-34                    ABC-1                          10.000
    1.000 A-109-347                 ABC-1                           2.000
    1.000 ABC-100G                  ABC-1                           1.000
    2.000 70052                     ABC-100G                       18.000
    2.000 M9532-278                 ABC-100G                        5.000
    1.000 1A247G01                  ABC-1                           2.000
    You mean you want don't want the descendants (children, grandchildren, etc.) of any component whose part_type is not 'M'.
    The part_type of the component itself doesn't matter: component '101-34' is included, even though its part_type is 'P', and component 'X525-101' is excluded, even though its part_type is 'M'.
    >
    Any suggestions?Sorry, I don't have an Oracle 8.1 database at hand now. All three of the queries below get the correct results in Oracle 10.2, and I don't believe they do anything that isn't allowed in 8.1.
    You can't do a join and CONNECT BY in the same query on Oracle 8.1.
    I believe you can do one first, then the other, using in-line views. The frist two queries do the join first.
    --     Query 1: Join First
    SELECT     LEVEL
    ,     component
    ,     parent
    ,     qty_per
    FROM     (     -- Begin in-line view to join bom_test and part_test
              SELECT     b.component
              ,     b.parent
              ,     b.qty_per
              ,     p.part_type     AS parent_type
              FROM     bom_test     b
              ,     part_test     p
              WHERE     p.part_nbr     = b.parent
         )     -- End in-line view to join bom_test and part_test
    START WITH     parent     = 'ABC-1'
    CONNECT BY     parent          = PRIOR component
         AND     parent_type     = 'M'
    ;Query 2 is very much like Query 1, but it does more filtering in the sub-query, returning only rows hose part_type or whose parent's part_type is 'M". Your desired result set will be a tree taken entirely from this set. Query 2 may be faster, because the sub-query is more selective, but then again, it may be slower because it has to do an extra join.
    {code}
    -- Query 2: Join first, prune in sub-query
    SELECT     LEVEL
    ,     component
    ,     parent
    ,     qty_per
    FROM     (     -- Begin in-line view to join bom_test and part_test
              SELECT     b.component
              ,     b.parent
              ,     b.qty_per
              ,     p.part_type     AS parent_type
              FROM     bom_test     b
              ,     part_test     p
              ,     part_test     c
              WHERE     p.part_nbr     = b.parent
              AND     c.part_nbr     = b.component
              AND     'M'          IN (c.part_type, p.part_type)
         )     -- End in-line view to join bom_test and part_test
    START WITH     parent     = 'ABC-1'
    CONNECT BY     parent          = PRIOR component
         AND     parent_type     = 'M'
    {code}
    Query 3, below, takes a completely different approach. It does the CONNECT BY query first, then does a join to see what the parent's part_type is. We can easily cut out all the nodes whose parent's part_type is not 'M', but that will leave components like 'R245-9010' whose parent has part_type 'M', but should be excluded because its parent is excluded. To get the correct results, we can do another CONNECT BY query, using the same START WITH and CONNECT BY conditions, but this time only looking at the pruhed results of the first CONNECT BY query.
    {code}
    --     Query 3: CONNECT BY, Prune, CONNECT BY again
    SELECT     LEVEL
    ,     component
    ,     parent
    ,     qty_per
    FROM     (     -- Begin in-line view of 'M' parts in hierarchy
              SELECT     h.component
              ,     h.parent
              ,     h.qty_per
              FROM     (     -- Begin in-line view h, hierarchy from bom_test
                        SELECT     component
                        ,     parent
                        ,     qty_per
                        FROM     bom_test
                        START WITH     parent     = 'ABC-1'
                        CONNECT BY     parent     = PRIOR component
                   ) h     -- End in-line view h, hierarchy from bom_test
              ,     part_test     p
              WHERE     p.part_nbr     = h.parent
              AND     p.part_type     = 'M'
         )     -- End in-line view of 'M' parts in hierarchy
    START WITH     parent     = 'ABC-1'
    CONNECT BY     parent     = PRIOR component
    {code}
    I suspect that Query 3 will be slower than the others, but if the CONNECT BY query is extremely selective, it may be better.
    It would be interesting to see your findings using the full tables. Please post your observations and the explain plan output.
    As usual, your message is a model of completeness and clarity:
    <ul>
    <li>good sample data,
    <li> posted in a way people can use it,
    <li>clear results,
    <li> good explanation
    <li> nciely formatted code
    </ul>
    Keep up the good work!

  • Help with Oracle Connection Pooling

    Hi,
    I want to create a connection pool that can be accessible in any jsp and in any class of my web application. Is it a good idea to create a class with a static member of type OracleDataSource or any class that handles connections?

    Rafa,
    In order to use JSP, you usually need an application server.
    Oracle's application server already has connection pooling built in.
    No need to re-invent the wheel.
    (In fact most application servers provide database connection pooling.)
    Good Luck,
    Avi.

  • Need Help with new site glitches PLEASE!!!

    I need help trouble shooting a website. The site is
    www.farrowandwatkins.com. Nav buttons on Mac they display correctly
    which is aligned at top and bottom of content to left on Home page.
    However, when viewed on PC, the buttons spread to fill the
    distance of the "Patients" Page. All the pages spread to this
    length also, but are not suppose to.
    Nav buttons have padding of 10 on bottom, except last one.
    Please help if you can

    First guess would be that there doesn't seem to be a fixed
    height or width on the cell for the 'patients' button.

  • I need help with the https class please.

    Hello, i need add an authentication field in my GET request using HTTPS to authenticate users. I put the authentication field using the setRequestProperty method, but it doesn't appear when i print all properties using the getRequestProperties method. I wrote the following code:
    try{
    URL url = new URL ("https://my_url..");
    URLConnection conexion;
    conexion = url.openConnection();
    conexion.setRequestProperty("Authorization",my_urlEncoder_string);
    conexion.setRequestProperty("Host",my_loginServer);
    HttpsURLConnection httpsConexion = (HttpsURLConnection) conexion;
    httpsConexion.setRequestMethod("GET");
    System.out.println("All properties\r\n: " + httpsConexion.getRequestProperties());
    }catch ....
    when i run the program it show the following text:
    All properties: {Host=[my_loginServer]}
    Only the Host field is added to my HttpsURLConnection. The authentication field doesnt appear in standar output. How can i add to my HttpsURLConnection an Authentication field?
    thanks

    I have moved this to the main Dreamweaver forum, as the other forum is intended to deal with the Getting Started video tutorial.
    The best way to get help with layout problems is to upload the files to a website and post the URL in the forum. Someone can then look at the code, and identify the problem. Judging from your description, it sounds as though the Document window is narrow, which would result in the final menu tab dropping down to the next row. Try turning on Live view or previewing the page in a browser. Design view gives only an approximate idea of the final layout. Live view renders the page as it should look in a browser.

  • I need help with my wifi sync, please?

    I am trying to sync a single band from my laptop to my iPhone. This is my new laptop and I have no transfered all my music from my old computer onto here, so I can not sync through the cable or else I will have to remove all my exsisting information on my phone, I do not have all my music on my laptop yet. All I want is to simply transfer a few songs from my iTunes to my phone wirelessly and I can't. I enabled the button when I plug in my phone that tells me I can sync wirelessly but when I disconnect it refuses to work. Please I need help.

    Dear friend, by the moment Blackberry playbook is just for USA/Canada users, in a very short time RIM will announce the release of the product for the rest of countries.
    Be patient when you can use it at 100%, you will be amazed!

  • I just bought my MacBook Pro 13" and I tried to install an anti virus but then it went into a grey folder with a question mark I need help with restoring the iOS please

    I need help taking out the grey folder with the question mark and I've try everything except the CD thing because my MacBook didn't come with one so I really need help please

    What anti-virus software did you install? Although there's a lot of bad anti-virus software out there, no anti-virus software should cause such a problem. A gray screen with a flashing question mark on a folder means that no bootable system could be found, which means that the system was badly damaged or corrupt. Even installing bad software would not normally cause that, so either there was something badly wrong with the system already or the anti-virus software you tried to install was really, really bad!
    As mende1 says, you need to reinstall the system at this point. After your system is back up and running, read my Mac Malware Guide. If, after reading that, you want anti-virus software, use one of the programms recommended in that guide.

  • Need help with iphone4 connecting to computer

    On the weekend my friend had put her iphone4 on my computer and now wen i connect my iphone4 to my computer it keeps saying that my iphone is her iphone but its not...
    I really need help coz its doin my head in, i have uninstalled the driver and itunes and reinstalled both and it still does the same thing

    try changing the following wireless settings
    radio band - wide
    wide channel - 9
    standard channel - 11
    if this doesn't work , ensure that the router has the latest firmware ..

  • I need help with the navigation menu please?

    I have been working my way through your six part printed instructions and I am styling the header and navigation menu.  The bullet points disappeared which was correct and the tabs moved to the right, as they should, but one tab sits underneath another tab and all tabs are covered up by my main heading.  This is dreamweaver CS6.
    It looks a bit of a mess!

    I have moved this to the main Dreamweaver forum, as the other forum is intended to deal with the Getting Started video tutorial.
    The best way to get help with layout problems is to upload the files to a website and post the URL in the forum. Someone can then look at the code, and identify the problem. Judging from your description, it sounds as though the Document window is narrow, which would result in the final menu tab dropping down to the next row. Try turning on Live view or previewing the page in a browser. Design view gives only an approximate idea of the final layout. Live view renders the page as it should look in a browser.

  • I need help with website can you please

    Need help
    Message was edited by: Liam Dilley - Phone number in here is a bad idea

    Hi,
    I removed your phone number as you will just get cold called
    BC support does not call you for help and people here can help you here. Just saying "need help" is not much use though, we need to know what kind of help you need.

Maybe you are looking for

  • More than one dataprovider for a datagrid

    Is there a way that i can provide more than one dataprovider with a comma or a semicolon seperated values in the datagrid? Since i need to display values from two different providers. Thanks, Geetha

  • Problem in displaying map.

    Hi I am not able to display the map in my device. I have downloaded the google map in my device and i am getting the error , if i start the application. The error is : "This application requires a data connection and some blackberry require reconfigu

  • Solution manager for performance monitoring

    Hi, We have implemented solution manager  in our project.Can anyone tell me how is this useful for performance monitoring and how can we check expensive sql statements using this. It would be helpful if anyone can provide me some documentation on thi

  • Qualifier values are not part of a qualified lookup record

    Hi      I am getting the exception "Qualifier values are not part of a qualified lookup record" when I serach for a record in the Qualified table. The Table has both Qualfier and non-Qualifier fields, but all are of type display fields. My question i

  • Split and mark the records

    Hi all, I have the below scenario where i need to mark every 4 records with a number. The count of ids can vary for example i am taking 10 id's. Can any one suggest a sql statement to achieve this. Thanks for looking into it. id         mark_id 1