Re: How to programatically limit the number of threads in a java

Posted by Marce... on 12. May 2015

On 12.05.15 17.49, Ajay Paul wrote:




How to programatically limit the number of threads in a java.




Simply do not start more threads than wanted. :-)
Java will not start more than one thread automatically.




I know the settings in different application servers such as websphere to do that,




Exactly. The number of threads need to be controlled by the application
that starts them. Web application servers are this kind of application.




but how do we do it programatically.




Not at all.



Even if the JVM could control that what should be the action when the
application requests another thread?
Throw a NoMoreThreadsException? This exception could not be reasonably
handled by the application. I.e. it will cause unexpected aborts or
other malfunction. The effect is comparable to out of memory exceptions,
since some libraries rely on the availability of (a limited number of)
threads, e.g. JMS or DBMS drivers. So basically you will need to restart
the application server after that exception.
Wait until another thread terminates? This is called a thread pool.
However, the application could deadlock, because the expected task may
not complete in a reasonable time, e.g. especially when other threads
wait for this one. Thread pools are commonly used by applications
servers but they must handle only independent requests.



Marcel


18. May 2015: Re: Main Loop porblm by Micha...

18. May 2015: Main Loop porblm by Micha...

18. May 2015: Re: Puzzler: Fun with Streams. by scatt...

18. May 2015: Re: Puzzler: Fun with Streams. by scatt...

17. May 2015: Re: get a list of classes at runtime by Arne ...

17. May 2015: Re: get a list of classes at runtime by Arne ...

16. May 2015: C*C*C: CIUCCIA CAZZI DI CAVALLO PAOLO BARRAI DI WMO E BSI ITALIA SRL, UNA VOLTA CACCIATO (E FATTO CONDANNARE A GALERA) DA CITIBANK, PRIMA DI SPENNARE POLLI VIA WEB, FECE FILM PEDOPORNOMOSESSUALI! E CON CAVALLI! CIUCCIANDO E PRENDENDO FALLI EQUINI E.. by CARME...

15. May 2015: Need Oracle DBA Resumes for the position in Chicago,IL by srini...

14. May 2015: About Java... by Ramin...

14. May 2015: Re: JNI Wrapper for Delphi and FreePascal version 2.82 is here.. by Ramin...

14. May 2015: JNI Wrapper for Delphi and FreePascal version 2.82 is here.. by Ramin...

14. May 2015: Re: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by ram a...

14. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Rober...

13. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

13. May 2015: Re: get a list of classes at runtime by Marti...

13. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

13. May 2015: Re: get a list of classes at runtime by Joshu...

13. May 2015: Re: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by Joshu...

13. May 2015: [Javascript] Uncaught ReferenceError: Invalid left-hand side in assignment by garlo...

13. May 2015: [Javascript] How do I find out what this bug means and how to fix it? Uncaught ReferenceError: Invalid left-hand side in assignment by garlo...

13. May 2015: Re: get a list of classes at runtime by j4n b...

13. May 2015: Re: get a list of classes at runtime by Joerg...

13. May 2015: Re: get a list of classes at runtime by Phili...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: Puzzler: Fun with Streams. by Danie...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: get a list of classes at runtime by Eric ...

13. May 2015: Re: How to programatically limit the number of threads in a java by Joerg...

13. May 2015: Re: get a list of classes at runtime by e d p...

13. May 2015: Re: Puzzler: Fun with Streams. by Jeff ...

13. May 2015: Call for Papers: World Congress on Engineering and Computer Science WCECS 2015 by iaeng...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

12. May 2015: Re: How to programatically limit the number of threads in a java by Marce...

12. May 2015: Re: JScrollPane not scrolling smoothly on fast computer by Knute...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

12. May 2015: Puzzler: Fun with Streams. by Danie...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Rober...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by ram a...

12. May 2015: Re: Use URL for HTTPS request using Proxy by Silvi...

12. May 2015: Use URL for HTTPS request using Proxy by Silvi...

12. May 2015: Re: what are the senarios when we should override equals and hashcode by Lew l...

12. May 2015: JNI Wrapper for Delphi and FreePascal version 2.8 by Ramin...

12. May 2015: Re: How to programatically limit the number of threads in a java by Eric ...

12. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Ajay ...

12. May 2015: How to programatically limit the number of threads in a java by Ajay ...

12. May 2015: Re: API vc MVC by Joerg...

12. May 2015: Need Java Developers/Tech Leads/Architects at Reston, VA (Permanent) by ashok...

11. May 2015: API vc MVC by Leona...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Gene ...

11. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by v_bor...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Joerg...

10. May 2015: Re: Animations with jTextPane by H L a...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: Animations with jTextPane by H L a...

10. May 2015: Re: Animations with jTextPane by Knute...

10. May 2015: Re: how does a marker interface give specific instruction to jvm(java internals) by Jeff ...

10. May 2015: how does a marker interface give specific instruction to jvm(java internals) by Ajay ...

10. May 2015: Animations with jTextPane by H L a...

09. May 2015: JScrollPane not scrolling smoothly on fast computer by Knute...

09. May 2015: PEZZO DI MERDA BASTARDO DAVIDE SERRA DI ALGEBRIS INVESTMENTS - TWITTER, HA RICEVUTO INSIDER SULLE POPOLARI DAL MEGALAVA SOLDI MAFIOSI PIER LUIGI BOSCHI DI BANCA ETRURIA! SON TUTTI NAZISTI, TIPO NOTO VERME PAOLO BARRAI DI WMO, CHE SI FINGON DEL PD X.. by CARME...

09. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

08. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by ram a...

08. May 2015: How to read the Java tutorial offline? by ram a...

08. May 2015: Re: best and worst sorting algorithm for 1 to 10,000 and then 10,000 + elements by Marti...

08. May 2015: Re: How to read the Java tutorial offline? by Jeff ...

06. May 2015: Re: Why Islam is the true religion of God. by Danci...

06. May 2015: CCC: CIUCCIA CAZZI DI CAVALLO PAOLO BARRAI DI CRIMINALI WMO E BSI ITALIA SRL, UNA VOLTA CACCIATO (E FATTO CONDANNARE AL CARCERE) DA CITIBANK, PRIMA DI SPENNARE POLLI NEL WEB, FECE FILM PEDOPORNOMOSESSUALI! E CON CAVALLI! CIUCCIANDO CAZZI EQUINI E ... by CHE S...

05. May 2015: Why Islam is the true religion of God. by BV BV...

04. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Marce...

04. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

04. May 2015: Re: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Eric ...

04. May 2015: best and worst sorting algorithm for 1 to 10, 000 and then 10, 000 + elements by Ajay ...

04. May 2015: Re: What is your favorite WC++IETJ? by ram a...

03. May 2015: Re: What is your favorite WC++IETJ? by Joshu...

03. May 2015: Re: what are the senarios when we should override equals and hashcode by Arne ...

03. May 2015: NAZIPEDERASTA SODOMIZZA BAMBINI: PAOLO BARRAI DI CRIMINALI WMO E BSI ITALIA SRL VIA SOCRATE 26 MILANO (OLTRE CHE MEGALAVA CASH MAFIOSO E POLITI-CRIMINALI)! STALKA A MORTE CHI LO FOTOGRAFA E SE "1 INSISTE", KILLER PAOLO BARRAI FA "SUICIDARE" DAVVERO!! by CARME...

03. May 2015: Re: what are the senarios when we should override equals and hashcode by ram a...

02. May 2015: what are the senarios when we should override equals and hashcode by Ajay ...

02. May 2015: imported maven project can't be recognized as java in eclipse by Ajay ...

02. May 2015: Re: Good example of EJB interface for CRUD operations by pavel...

01. May 2015: Very urgent requirement || Technical Lead - .Net @ Golden Valley, MN by Vasan...

01. May 2015: Re: If java doesn't support operator overloading, how does String + concatenation work by v_bor...

30. Apr 2015: Re: If java doesn't support operator overloading, how does String + concatenation work by Rober...

30. Apr 2015: Re: What is your favorite WC++IETJ? by Robbi...

30. Apr 2015: Re: What is your favorite WC++IETJ? by Sebas...

30. Apr 2015: Re: What is your favorite WC++IETJ? by ram a...

30. Apr 2015: Re: What is your favorite WC++IETJ? by ram a...

30. Apr 2015: Re: What is your favorite WC++IETJ? by Jerry...

30. Apr 2015: What is your favorite WC++IETJ? by ram a...

30. Apr 2015: Re: If java doesn't support operator overloading, how does String + concatenation work by Eric ...

30. Apr 2015: Re: What is your favorite WC++IETJ? by Eric ...

30. Apr 2015: Re: Easy exhaustive search with Java 8 Streams by j4n b...

30. Apr 2015: If java doesn't support operator overloading, how does String + concatenation work by Ajay ...

29. Apr 2015: Re: Easy exhaustive search with Java 8 Streams by Sebas...

29. Apr 2015: Re: Easy exhaustive search with Java 8 Streams by Sebas...

29. Apr 2015: Re: Survey Request for Research related to Software Engineering and Social Media by Jerry...

29. Apr 2015: Survey Request for Research related to Software Engineering and Social Media by Augus...