Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
JSP - A mailing list about Java Server Pages specification and reference
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Singleton class issue

Singleton class issue

2004-11-17       - By Binildas

 Back
Reply:     1     2     3     4     5  

Bill,



The simplest (and preferred) method is to design the methods inside your
singleton class as idempotent. This can be achieved by not using any
writable, instance fields in your singleton class. If so, even if the
methods are executed concurrently by multiple threads (either in a
single CPU or multiple CPU m/c), each thread will be executing in its
"separate, local stack memory" only.



Regards



Binildas
Senior Technical Architect

http://www.infosys.com <http://www.infosys.com/>



-- --Original Message-- --
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
[mailto:J2EE-INTEREST@(protected)] On Behalf Of bin cai
Sent: Thursday, November 18, 2004 7:41 AM
To: J2EE-INTEREST@(protected)
Subject: Singleton class issue



Hello,

I am developing web application based on j2ee technology:jsp, java bean
and jdbc.

I ceated a singleton class called "JdbcController.java" that takes the
responsibility to establishing   connection to DB and works fine. But my
concern is :since this is multi-thread application. every thread will
invoke JDBCController class . i am wondering if this will result in
concurrent issue becase every thread will compete to use this class to
get connection to DB.

one alternative is :i don't use singleton pattern. when every thread
needs to get access to DB, it will ceate new instance of JDBCControoler
object. but it will use lot of memory although JVM has garbage
collection mechanism.

So which way is better according to you guys' experience. Please let me
know.

Thanks

bill

__ ____ ____ ____ ____ ____ ____ ____ ____ ____ __
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
========================================================================
=== To unsubscribe, send email to listserv@(protected) and include in
the body of the message "signoff J2EE-INTEREST". For general help, send
email to listserv@(protected) and include in the body of the message
"help".


===========================================================================
To unsubscribe, send email to listserv@(protected) and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@(protected) and include in the body of the message "help".


<html>

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">


<meta name=Generator content="Microsoft Word 10 (filtered)">

<style>
<!--
/* Font Definitions */
@(protected)
       {font-family:Tahoma;
       panose-1 (See http://ose-1.ora-code.com):2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
       {margin:0in;
       margin-bottom:.0001pt;
       font-size:12.0pt;
       font-family:"Times New Roman";}
a:link, span.MsoHyperlink
       {color:blue;
       text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
       {color:purple;
       text-decoration:underline;}
p
       {margin-right:0in;
       margin-left:0in;
       font-size:12.0pt;
       font-family:"Times New Roman";}
span.EmailStyle18
       {font-family:Arial;
       color:navy;}
@(protected) Section1
       {size:8.5in 11.0in;
       margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
       {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Bill,</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The simplest (and preferred) method is to
design the methods inside your singleton class as idempotent. This can be
achieved
by not using any writable, instance fields in your singleton class. If so, even
if the methods are executed concurrently by multiple threads (either in a
single CPU or multiple CPU m/c), each thread will be executing in its &#8220
;separate,
local stack memory&#8221; only.</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Regards </span></font></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Binildas<br>
Senior Technical Architect</span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><a href="http://www.infosys.com/">http://www.infosys.com</a>
</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'>-- --Original Message-- --<br>
<b><span style='font-weight:bold'>From:</span></b> A mailing list for Java(tm)
2 Platform, Enterprise Edition [mailto:J2EE-INTEREST@(protected)] <b><span
style='font-weight:bold'>On Behalf Of </span></b>bin cai<br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, November 18, 2004
7:41 AM<br>
<b><span style='font-weight:bold'>To:</span></b> J2EE-INTEREST@(protected)<br>
<b><span style='font-weight:bold'>Subject:</span></b> Singleton class issue<
/span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>Hello,</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>I am developing web application based on j2ee
technology:jsp, java bean and jdbc.</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>I ceated a singleton class called
&quot;JdbcController.java&quot; that takes the responsibility to&nbsp
;establishing&nbsp;&nbsp;
connection to DB and works fine. But my concern is :since&nbsp;this is
multi-thread application. every thread will
invoke&nbsp;JDBCController&nbsp;class&nbsp;. i am wondering if this will result
in concurrent issue becase every thread will compete to use this class to get
connection to DB.</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>one alternative is :i don't use singleton pattern.
when every thread needs to get access to DB, it will ceate new&nbsp;instance of
JDBCControoler&nbsp;object.&nbsp;but it will use lot of memory although JVM has
garbage collection mechanism.</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>So which&nbsp;way is better according to you guys'
experience. Please let me know.</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>Thanks</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"
><span
style='font-size:12.0pt'>bill&nbsp;&nbsp;</span></font></p>

</div>

<p style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>__ ____ ____ ____ ____ ____ ____ ____ ____ ____ __<br>
Do You Yahoo!?<br>
Tired of spam? Yahoo! Mail has the best spam protection around <br>
http://mail.yahoo.com =========================================================
==================
To unsubscribe, send email to listserv@(protected) and include in the body of
the message &quot;signoff J2EE-INTEREST&quot;. For general help, send email to
listserv@(protected) and include in the body of the message &quot;help&quot;.
</span></font></p>

</div>

</body>

</html>
===========================================================================
To unsubscribe, send email to listserv@(protected) and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@(protected) and include in the body of the message "help".
<p>

©2008 junlu.com - Jax Systems, LLC, U.S.A.