*IMPORTANT* Limiting the number of active threads

Hi All,
i have a few of questions so please bare with me:
1) What is the best way to limit the number of active threads? ie i want to run 10 threads but i want there to be only 3 running at a time.
this is how im thinking of doing it rite now:
count = 0;
while(...)
thread[count].start();
while(threadgroup.activeCount > 4){}
count++;
2) I have a class that extends thread how do i overide the constructor so that i can add the thread to the threadgroup?
ok here is an example of what i mean:
u can do this with a normal thread: Thread one = new Thread(threadgroup, "what");
this is what i need to do tho:
class whatever extends Thread {
public whatever(int a, int b, ThreadGroup tg)
{ what do i put here to make this thread part of the tg threadgroup?}
thanx for any help in advance and i kinda need a quick answer cause this is due soon , thanx youssefe2k4

Hi,
1) Why do you want to do that?
2) super(tg, "a name");
/KajIt's part of a homework assignment... I saw another post on this forum and one at JavaRanch where you need to create an application that given a directory will scan each file and report the file name and how many lines are in them... but it must be multithreaded, each thread scan a single file and updates some list and finally you can only have three of these file scanning threads running at the same time...
Quote "To avoid having too many threads competing for the system resources when there are a lot of files in the directory, we will restrict the number of active Producer threads (active threads are started threads that have not ended yet) during the run time. For this assignment, at any time there should not be more than 3 active Producer threads. If there are already three active Producer threads during the run time, the program should wait until one of them ends to start the next Producer thread."
I was think about working on it, so that I can strengthen my knowledge in threads...
I still might do it, just for fun... I don't know yet...
We will see...
- MaxxDmg...
- ' He who never sleeps... '

Similar Messages

  • Does Java self-limit the number of active threads?

    I was hoping someone might be able to shed some light on this:
    I basically have a loop which creates an instance of a class that extends Thread. This class, lets call it MyTask, may take a minute or two to run. In my run() method I system.out an ID as soon as the .start() is actioned, like this:
    class MyTask extends Thread
    int nMyID;
    public MyTask(int vnMyID)
    this.nMyID = vnMyID;
    public void run()
    System.out.println(this.nMyID);
    // do other stuff that takes a couple of mins...
    ThirdPartyAPI.dosomething();
    In my loop I create an instance of MyTask and call the .start() method on it.
    What I'm seeing is that rather than the ID being outputted immediately as I would expect, the IDs are being outputted over a period of time, so this to me would imply that Java is queuing the threads before starting them? I don't want it to queue the treads because the rest of MyTask is simply sat waiting for a response from a third party system. It gets through them all eventually, but it just takes a long time, and it should be quicker.
    Is there anything I can do to stop it from behaving this way?
    Thank you

    BigBadBurrow wrote:
    I was hoping someone might be able to shed some light on this:
    I basically have a loop which creates an instance of a class that extends Thread. Unrelated to your problem, but just as a side note, that's poor design. You're almost certainly not creating a specialized kind of Thread, but rather, a task to be run in its own thread, and hence you should implement Runnable.
    This class, lets call it MyTask, may take a minute or two to run. In my run() method I system.out an ID as soon as the .start() is actioned, like this:
    class MyTask extends Thread
    int nMyID;
    public MyTask(int vnMyID)
    this.nMyID = vnMyID;
    public void run()
    System.out.println(this.nMyID);
    // do other stuff that takes a couple of mins...
    ThirdPartyAPI.dosomething();
    In my loop I create an instance of MyTask and call the .start() method on it.
    What I'm seeing is that rather than the ID being outputted immediately as I would expect, the IDs are being outputted over a period of timeProvide an [url http://sscce.org]SSCCE
    , so this to me would imply that Java is queuing the threads before starting them? Not generally, no. However, once you've started the other threads, you now have those threads running plus your main thread. If your main thread goes on to do some CPU intensive work, it might be some time before the other threads get cycles. Anytime you have more threads the CPUs/cores, there will be at least one thread that's waiting. You don't (and shouldn't need to) control which thread gets CPU when.

  • BPEL Client API - Query Domain for Number of Active Threads ?

    Hi,
    Is there a method to query the number of active threads within the domain ? i.e. the same value displayed under Thread Allocation Activity shown on http://localhost/BPELConsole/default/domain.jsp?mode=thread
    I've browsed the API docs but can't find a way to do this... I might have missed something thought.
    Cheers,
    Rob

    Thanks Marc.
    How would I go about getting a domain handle ? The bit I'm stuck on in obtaining the initial authenticated connection to the server. The ngThreadInfo code does this:
    Server server = ServletUtils.getServer( request, response );
    String token = server.getServerAuth().getToken();
    and I guess the request/response vars provide the security context in which the getServerAuth operates ?
    Which API functions can I embed in a BPEL process to connect to the server and subsequently obtain the domain handle ?
    Cheers,
    Rob J.

  • In this iPhone is activated limiting the number of free accounts

    I would like to use on your iphone 4s ICloud, but when I try to run ICloud appears in this iPhone is activated limiting the number of free accounts. What do I do? p.s( Sorry for the broken English)

    Make the accounts on a computer. I believe the iPhone is limited
    to creating 3 accounts.

  • Why do the number of active JMS connections increase?

    <strong>Problem</strong>
    - Number of active JMS connections and current JMS messages increases until the Weblogic instances crash with an OutOfMemory exception
    <strong>Setup</strong>
    - Weblogic v9.2.3, Cluster with 4 Nodes
    - A JMS Message is sent from a MDB in Weblogic to a distributed queue which has a member on each of the 4 Weblogic nodes. The session is created as follows session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE), the message delivery mode is set programmatically to persistent and the delivery mode override of the queue setup is set to persistent too
    - Standalone JMS client processes: each one is attached to <strong>all</strong> 4 nodes. Each one uses a unique JMS message selector so that we have more than one queue consumer for one queue but every message is exactly dedicated to one queue consumer. We us weblogic.jar for the clients.
    - Use of Weblogic auto reconnect feature. JMS client code:
    Connection connection = this.connectionFactory.createQueueConnection();
    final WLConnection wlconnection = (WLConnection)connection;
    wlconnection.setReconnectPolicy(JMSConstants.RECONNECT_POLICY_ALL);
    wlconnection.setTotalReconnectPeriodMillis(-1);
    wlconnection.setReconnectBlockingMillis(-1);
    <strong>Remarks and Questions</strong>
    - There are no pending JMS messages which is good
    - In our setup, each JMS client is connected to all 4 nodes as the messages are not distributed to all nodes: if a message is put to Queue A but the client is only connected to Queue B, the message is NOT transfered from Queue A to Queue B. We set the parameter "Forward Delay" to 5 seconds with no effects. Is this the normal behavior?
    - Not all JMS clients are visible in the Weblogic console under JMS Services -&gt; JMS Servers -&gt; [Server] -&gt; Monitoring -&gt; Active Connections. Which one are visible? Which one are not visible? There are also clients where the number of connections is not zero but stays constant; we know that as several independent clients on different hosts are started and the IP adress is visible in the Weblogic console. Why....?
    - What reasons can lead to increasing connections? Is this due to client or server problems? Do we have to acknowledge the message in the onMessage(Message) method of the client JMS consumer? So far as I know, we don't have to.
    - Are the increasing number of current messages due to the increasing number of JMS connections?
    - May the RECONNECT_POLICY_ALL policy produce this problem?
    Any hint is appreciated.
    Peter
    Edited by: pkeller on 23.10.2008 17:08

    To answer the question about the forwarding of messages from one queue to another myself: As mentioned at http://forums.bea.com/thread.jspa?threadID=400000611, the forwarding for queues does only work if all queue consumers are attached to the same queue. This means that our setup is OK.
    But the main question is still unanswered: why do the number of active JMS connections increase? I forgot to mention that
    - all messages arrive at the clients and that no exceptions are visible in the log
    - if you kill the client, the connections are still visible in the Weblogic console!?
    Please help as this problem is very urgent.
    Peter
    Edited by: pkeller on 24.10.2008 09:06
    Edited by: pkeller on 24.10.2008 09:10

  • The number of active sessions isn't decreasing in OC4J instance

    Hi Guru’s,
    Could you help me, please?
    The number of active sessions isn’t decreasing in OC4J instance after our clients closed the application.
    Our partner use Oracle AS 10gR3 (10.1.3.4.0) with J2EE and HTTP mode.
    When we monitoring our OC4J instance with Performance tab on Oracle EM, we appreciate that the value of Active Sessions on ‘Servlets and JSPs’ are very high. If users close our applications, then number of active sessions isn’t decreasing and active status isn’t becoming inactive.
    Which OC4J settings responsible for managing active sessions and how can I get more information about the active session details?
    Thanks in advance,
    Zoltan

    Dinesh.Rajak wrote:
    When I deployed this code Tomcat, it is giving the output as 0, hence tried with accessing the jsp file in multiple browsers but still it is showing the count of active session as 0 - plz helpPlease, don't resurrect old threads, and it's still the wrong forum. Create a new thread if you have a specific question, and create the thread in the correct forum. I'm closing this thread.
    Kaj

  • Server Administrator has Limited the Number of Items You Can Open Simultaneously

    Over the weekend, we moved all of our room mailboxes over to Exchange. For users who have lots of room calendars open in their Outlook clients, they are getting the error message "Cannot Open the free/busy information. You Server Administrator has Limited
    the Number of Items You Can Open Simultaneously" after the migration from Exchange 2010.
    Restarting the Outlook client temporary fixes the problem, but the problem comes back after they access the calendars again.
    The users impacted deal with a lot of room scheduling, so they have 30+ room calendars open in their Outlook clients.
    I have tried setting up a throttling policy with unlimited RCA connections, but that didn't help.
    I have seen with Exchange 2010 there were some registry keys people were setting on the server that pretty much makes everybody have unlimited connections, but that isn't ideal if's only affecting a few people.

    Hi,
    Since this issue only occurs to a few users, I recommend you disable all the third-party applications on Windows, especially for the desktop search apps. Meanwhile, use Outlook safe mode to disable all the add-ins and check if the issue persists.
    If the issue persists, you need to reset the value of Maximum Allowed Sessions Per User. Besides, we can't set it for only some specified users.
    Here is a thread for your reference.
    Event 9646, MSExchangeIS - Mapi session exceeded the maximum (Note: Though it is Exchange 2010, it also applies to Exchange 2013 about this issue)
    https://social.technet.microsoft.com/Forums/exchange/en-US/91922b60-38b7-4af3-ba13-3b44949cc9f7/event-9646-msexchangeis-mapi-session-exceeded-the-maximum-exchange-2010-sp1-w-update-roll-up-2?forum=exchange2010
    Hope this can be helpful.
    Best regards,
    If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Amy Wang
    TechNet Community Support

  • How to control the number of running thread

    I need to maintain the number of running thread in the system or in a threadgroup, as too many running thread will make the system throughput drop tremendously because of the context swtich and memory problem. The threadgroup is not a solution as its active count is the number of the threads that are alive, it includes the thread being blocked as well. I don't know whether there is any way to control it without the use of an expensive monitor?
    Thanks for any help

    If you create a pool of any sort you will need a point where all requests for a resource from the pool must go via, and that piece of code could potentially become a bottle neck. But if you develop it well there will be a very small piece of code that is sychrnonized that will either put a request in a queue as there are no resources available, or it will provide the requested resource. As far as i am aware there is no safe way around this as you will have multiple threads requesting the resource.

  • Report showing the number of active users in the system

    All,
    There is a standard SAP report which shows the number of active users in the system (output same as AL08).
    Does anyone remember this?
    Cheers,
    Bidwan

    Hello Bidwan, 
    Are you talking about the report RSUSR000?
    Regards.
    Ruchit.

  • After upgrading to Firefox 8.0.1, now on at least one website I use, it limits the number of characters that I can type in a text box to 275, is there a way to fix this?

    After upgrading to Firefox 8.0.1, now on at least one website I use, it limits the number of characters that I can type in a text box to 275, is there a way to fix this?

    That may be part of the coding that the web page is using.
    *https://developer.mozilla.org/en/HTML/element/input

  • Check the number of active users of oc4j in EBS

    Hi,
    I often see a recommndation of sizing jvm's to 1 per 100 active users. How can I find the number of active users currently using a jvm in EBS. We have 4 apps servers and 1 of apps servers also runs OBIEE with it's own jvm.
    I can find out from a unix command prompt counting establish connections to the port but I like to know if there's a better way to find the number of active users using the jvm's
    Thanks
    Mike

    Hi,
    To find the number of active user session on each of the application servers from a unix command line. I would find the port that Apache was listening on eg 8100. The use the following command on each of the apps servers
    netstat -an | grep 8100 | grep -i est | wc -l
    This gives a rough idea of how many active connections are established to the apps server. But I would really like to find how many users are actively using o4cj.
    If you are using forms in socket mode again, you can grep on the forms listening port number to find how many active forms users are connected.
    I can also see how many active connections are in the oc4j established to the database using lsof. Find the process id for oacore jvm.
    lsof -p PID
    But I'm sure there's a better and more accurate way of find active users of o4cj, specifically oacore.
    Thanks
    Mike

  • Getting the number of active connections in a connection Pool

    Hi,
    I have an application deployed on jboss. DB used is db2. For monitoring purpose i need to get the number of active and idle connections at any point of time. I am trying to use commons-dbcp jar to get this data using BasicDataSourceClass. Following is the piece of code.
    Context initialContext;
    try {
         initialContext = new InitialContext();
         DataSource ds = (DataSource) initialContext.lookup(myjndiname);
         logger.info("************CONNECTION POOL DATA->" + ds.getClass().getName() + "************" + ds.getClass() + "**************");
         BasicDataSource bds = (BasicDataSource) datasource;
              logger.info("************CONNECTION POOL DATA-> ACTIVE CONN=" + bds.getNumActive() + " IDLE CONN=" + bds.getNumIdle() + " INIT SIZE=" + bds.getInitialSize());
    catch (NamingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    This code gave a class cast exception at the point datasource is cast to BasicDataSource. The class name returned by ds is WrapperDataSource. I have few queries on this:-
    1. What configurations do i need so that datasource returned by InitialContext is BasicDataSource? FYI i tried to add the BasicDataSourceFactory in db2-ds.xml. But it still didnt work
    2. Is there any other way to find the number of active connections in a connection pool? I dont want any server specific solution.
    Pls help.
    Thanks

    user13642196 wrote:
    Hi,
    I have an application deployed on jboss. DB used is db2. For monitoring purpose i need to get the number of active and idle connections at any point of time. I am trying to use commons-dbcp jar to get this data using BasicDataSourceClass. Following is the piece of code.
    Context initialContext;
    try {
                 initialContext = new InitialContext();
                 DataSource ds = (DataSource) initialContext.lookup(myjndiname);
                 logger.info("************CONNECTION POOL DATA->" + ds.getClass().getName() + "************" + ds.getClass() + "**************");
                 BasicDataSource bds = (BasicDataSource) datasource;
              logger.info("************CONNECTION POOL DATA-> ACTIVE CONN=" + bds.getNumActive() + "  IDLE CONN=" + bds.getNumIdle() + "   INIT SIZE=" + bds.getInitialSize());
    catch (NamingException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
    }This code gave a class cast exception at the point datasource is cast to BasicDataSource. The class name returned by ds is WrapperDataSource. You can only cast an object to an interface it implements or to a class it extends (directly or indirectly).
    I have few queries on this:-
    1. What configurations do i need so that datasource returned by InitialContext is BasicDataSource? FYI i tried to add the BasicDataSourceFactory in db2-ds.xml. But it still didnt workhttp://commons.apache.org/dbcp/api-1.2.2/org/apache/commons/dbcp/package-summary.html#package_description

  • How to know the number of Active users logged in to a Essbase  Application?

    Hi,
    Is there way to capture/log the number of active users who have logged into a particular Essbase application at a given time.
    In Essbase or in Shared services?
    I know we can see the EAS-Edit Sessions shows the actively logged-in users, then we can sort on the application/database & manually count the number.
    Is there a way to capture it in a log at a given time on a regular basis. Any MAXL or Shared services feature?
    Appreciate your thoughts.
    Thanks,
    Ethan.

    You could use maxl .
    display user all;
    there will be a column called "logged in" which will display true/false for the users
    but that will just show if they are logged into the server and not the application
    You can also use use display session
    display session all;
    or
    display session on application sample;
    which should show what you are after.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How do I reset the number of activations on Visio 2003 after getting a "too many activations" message?

    I just installed Visio 2003 on a PC, and got the "we can't activate this app via the internet because you've installed it too many times" message. I went back to phone activation, but, of course, that's no longer available for this product.
    How do I get the number of activations reset? Apparently you used to be able to do this by calling Microsoft, but what's the number to call? Or is there another way to do it?
    I'm probably going to need to do it for my copy of Office 2003 also.

    Hi,
    Microsoft has ended support for Office 2003 on April 8, 2014. This change will affect your software updates and security options.
    Please contact your local customer service. Explain to the service (Human being) that you can’t activate Visio 2003 and the error message is “we can't
    activate this app via the internet because you've installed it too many times”.
    You can find
    your local custom support number on the link below.http://support.microsoft.com/gp/customer-service-phone-numbers/en-us
    Hope it can be helpful.

  • What limits the number of MII connections to Oracle.

    We are using MII 12.0.5 and an Oracle database and are seeing errors in the logs to the effect:
    SQL error occurred on connection jdbc:oracle:thin:@mii001:1527:SMD: code=0, state="null", message="Listener refused the connection with the following error:
    ORA-12518, TNS:listener could not hand off client connection
    The Connection descriptor used by the client was:
    mii001:1527:SMD
    I am ot an Oracle expert and I have not seen this issue before. What is limiting the number of connections? Is this a MII configuration issue that I am not aware of or an Oracle database issue?

    Hello sparks,
    I assume you are getting this error when you are trying to connect to databse while configuring Dataservers in MII,if fo what are the value you passed in the fields PoolMax and PoolSize while connecting to the database.
    Regards,
    Kumar
    Edited by: Sudhir Kumar Shambana on May 6, 2010 10:50 AM

Maybe you are looking for

  • After upgrading to iOS 8 I can not open iTunes and iTunes store. Furthermore I cannot even update my app like Facebook etc

    I Upgraded my iPad mini with retina screen 16 GB to iOS 8. I'm facing weird issues..i can't open iTunes , itunes store and can't upgrade app which I have downloaded..furthermore my iPad became slow..I don't understand what to do...please help me

  • Temperature Dirplay Panel For Geforce FX?

    I bought an MSI GeforceFX 5200 (TDR-128). In the past i have seen a temperature display panel in one of the nvidia display panels, when i was surfing. I have the latest drivers from nvidia (45.23), plus the "coolbits", but i cant see this temperature

  • ABAP Webdynpro Linktoaction in table

    Hi, In my webdynro view i have a table with some fields as linktoaction. In the context for table following attributes are set: Initialize Lead Selection = 'X' Singleton = 'X' How can I get the row where the linktoaction is clicked on in the correspo

  • Pse6 MAC - Multiple File Processing Problem

    Hi - I have been using the PSE 6 MAC and processing multiple files converting from Camera Raw to JPGs.  All of a sudden, it won't run any more.  Gets stuck somewhere in the first picture and hangs up.  Anyone have any ideas?  I've rebooted and checke

  • Change frame rate on an AC3 files?

    I've been given two NTSC (23.98 fps) .ac3 files (5.1 Dolby Digital EX and 6.1 DTS-ES) that I need to use in a PAL 25fps project. Any suggestions as to how to change the frame rate to match my PAL encodes?