Thread Safe Issue with Servlet

I saw the following statement in one of the J2EE compliant server documentations:
"By default, servlets are not thread-safe. The methods in a single servlet instance are usually executed numerous times simultaneously (up to the available memory limit)."
I'm quite concerned with this statement for the primary reason that (I'm trying to reason by reading it out loud) servlets are not going to be thread-safe especially when available memory hit really really low!! So, when the application is still having sufficient memory, we will not likely run into concurrency problems, i.e the happy scenario for a short period after server is started. BUT, good things don't last long.. Anyway, hope someone can explain to me with more insights. Thanks.

Don't worry, memory occupation and thread safety are not related at all.
In my opinion, the following is the meaning of the statement you quote.
Since the servlet specification doesn't force any implementation to spawn a new servlet object upon each request (and this should be a real memory hit!), nor to synchronize calls to servlet methods, you should always code your servlet in a "stateless" fashion: you should be aware the same method on the same object could (and probably will) be called concurrently if multiple concurrent client requests are submitted.
Hope I've been clear enough...

Similar Messages

  • Thread Safety Issue with DOM

    I am parsing an XML into a DOM object using the Xerces parser that is packaged with JDK 1.5.
    First, I create a new instance of the DocumentBuilderFactory and then using the factory, create a new DocumentBuilder. I then parse the XML using the DocumentBuilder to obtain a DOM object.
    Somehow, I am seeing the same DOM object being used for different XMLs.
    Is there a thread safety issue with the Xerces parser?

    certainly, Xerces parser is not thread safe. You have to provide thread safety by making sure that only one thread is allowed to access DocumentBuilder object.

  • RDBMS non-thread-safe issue

    <snip>
    This (as you probably know) is due to the fact that the code provided by
    most of the DB vendors is not thread safe.
    <snip>
    Sean's comment, above, speaks to an issue that is causing some concern
    within my (large - 180 projects in development) organisation.
    May I please ask the forum if there are others out there who have an
    understanding of / concern with this "problem"?
    My perception (quite possibly flawed) of the "problem" is that the RDBMS
    cannot multi-thread data access objects. So we find ourselves in a situation
    where we can achieve scaleability in just about all other
    performance-sensitive areas of a system's technical architecture (we're
    using DCE -- but have found that Encina is not advisable except where there
    is a true requirement for heterogeneous distributed 2 phase commit, which we
    don't often see.....) but when we go to hit on the RDBMS, we go back to good
    ole single-threading.
    In certain circumstances, this shortfall of RDBMS technology -- I won't
    mention any names, of course, but the initials are "Oracle" -- seems to be
    hindering our achievement of a desired technical architecture.
    Is this a "Pro*C / PL/SQL stored procedures" problem or is it something that
    is in the RDBMSs' DNA?
    How can we get around it?
    Any comments?
    Regards
    Jon

    Jon
    I agree. But it is the best solution within the constraints of existing
    technology. At least we don't use a process per client. 10 replicated
    copies of a service could service the needs of 100 clients.
    Eric
    >
    At 13:15 6/09/96 EST, you wrote:
    Eric
    Thanks for your response. Yep. I realise that the issue I've presented is
    clearly not something that Forte causes or is responsible for in any way.
    Forte can, as you've pointed out, actually help in this area. But I don't
    think that getting Forte to spawn another instance of a data access server
    is really the best solution. Ie, that's not what we tend to have in mind
    when we think about "scaleability". The best solution is -- perhaps -- to
    get the RDBMS people to thread-safe all code and libraries. I have pointedly
    asked Oracle for a position on this -- and got the usual blank stare.
    I also considered whether people might get upset at me for posting what is
    clearly a non-Forte-specifc question in a Forte forum. But then I went ahead
    and did it anyway. Justification being (assumption follows) that the kind of
    people who hang out on the Forte forum may tend to be more
    architecture-oriented than your run of the mill VB / SQL*Net / PL/SQL stored
    procedures kinda guy/gal, and may be using or considering Forte (plug for
    Forte follows) precisely because it clearly enables a superior architecture.
    Should proably post to the comp.database.oracle forum, but I just don't know
    them as well.
    Regards
    Jon
    From: Eric Gold
    To: McLeod, Jon
    Cc: [email protected]
    Subject: Re: RDBMS non-thread-safe issue
    Date: Friday, 6 September 1996 11:21AM
    Jon
    In response to this message.....read below...
    Sean's comment, above, speaks to an issue that is causing some concern
    within my (large - 180 projects in development) organisation.
    May I please ask the forum if there are others out there who have an
    understanding of / concern with this "problem"?
    My perception (quite possibly flawed) of the "problem" is that the RDBMS
    cannot multi-thread data access objects. So we find ourselves in a situation
    where we can achieve scaleability in just about all other
    performance-sensitive areas of a system's technical architecture (we're
    using DCE -- but have found that Encina is not advisable except where there
    is a true requirement for heterogeneous distributed 2 phase commit, which we
    don't often see.....) but when we go to hit on the RDBMS, we go back to good
    ole single-threading.
    In certain circumstances, this shortfall of RDBMS technology -- I won't
    mention any names, of course, but the initials are "Oracle" -- seems to be
    hindering our achievement of a desired technical architecture.
    Is this a "Pro*C / PL/SQL stored procedures" problem or is it something that
    is in the RDBMSs' DNA?
    How can we get around it?
    Any comments?Jon,
    Go ahead ask the Forum any questions you want. This "problem"
    is not a problem in Forte. What we allow you to do is "replicate" your
    data access services so that each one runs inside its own
    process. Each one of these processes (aka partitions) has its
    own connection to the database. The routing to the replicated
    partitions is transparent to the clients. Clients send a
    message like "DatabaseService.GetCustomer()" and then the Forte
    router sees which replicated copy of the service is not currently
    processing a request and routes it to that free replicate. You
    can dynamically increase or decrease the number of replicated
    copies of the service easily.
    We call this feature "load balancing" in Forte. It is achieved
    by checking a box in the data access service object definition.
    You can dynamically increase/decrease the number of replicates
    and also dynamically move replicates to other nodes in the environment.
    This approach assumes that you are using application driven
    security and not database security. Each replicated copy
    of the service is using the same generic username/password
    to connect to the database.
    I am forwarding this answer to forte-users because others
    might not completely understand this feature.
    Eric
    Eric Gold
    Technical Director
    Forte Australia
    Voice: 61-2-9926-1403
    Fax: 61-2-9926-1401
    Eric Gold
    Technical Director
    Forte Australia
    Voice: 61-2-9926-1403
    Fax: 61-2-9926-1401

  • THREAD SAFETY ISSUE OF SERVLET

    It is possible that one instance of a sevlet is accessed by multiple
    client , then how is the concurrency issue taken care of? Especually thread safety?

    It's not, you have to handle it yourself.
    That's why it's a good idea to never put instance variables in servlets. The basic technique is to store anything you need to save between requests in the current user's session (which you get by calling request.getSession()). During a call to service() (or, more frequently, to doGet or doPost, you're safe if you use whatever is present in the request and response argument, including servlet config parameters, request parameters, request attributes, and session attributes.
    If you want to write some "real" servlet app, you should have a look at one of the frameworks, like Jakarta Struts or OpenSymphony WebWorks.

  • NetBeans problem: Issue with servlets and Chinese character encoding

    Java Version: JDK1.5.0_01, JRE1.5.0_01 (International version)
    Netbeans Version: Netbeans IDE 4.0
    OS: Windows XP Personal Edition
    Dear Sirs,
    First at all thanks for reading this post. I am having the following issue. I am creating an application using html pages and servlets. I am using Chinese and English languages on them (html encoding UTF-8).
    I created a project in Netbeans and added an idex.html screen reporting to a servlet. Both index.html and in the servlet generated html page contains the line:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    Additional, I setup the character code settings in Netbeans:
    (tools-options-Java sources-Expert-default encoding=UTF-8
    When I run the project, index.html displays itself perfectly, with the Chinese characters displayed properly. The problem comes when the html created servlet is displayed, which instead of the Chinese characters some strange characters are displayed (�� instead of Chinese).
    I have tried different encodings from http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html without any luck. I also setup the encoding of the file itself (using right click-properties in the project menu of Netbeans).
    Also, when I am editing the servlet, the characters are displayed properly. I type them directly without any issue, but then the display is wrong at runtime.
    Also, just in case this have something to do with the problem, my PC was bought in US, therefore the default character set is not Chinese. I had to install the Chinese typing stuff later on. But like I said earlier, the html page is displayed properly, so I really think is some problem with Netbeans.
    After a week trying to find a solution, I decided to post it here in the hopes that someone will show me the way of the light.
    Thanks in advance for any ideas or help provided
    Aral.

    Ok, I found out some problems with Netbeans as well.
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response)
            throws IOException, ServletException
            response.setCharacterEncoding("UTF-8");
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            byte[] st = {-25,-75,-124,-27,-100,-106,-17,-68,-102,-27,-80,-113,-27,-72,-125,-26,-118,-75,-26,-105,-91,-27,-82,-93};
            out.println("this works: ");
            out.println(new String(st,"UTF-8"));
            out.println("<br>");
            out.println("this doesn't: ");
            out.println("some chinese copied from the Internet<br>");Right click the .java file and choose properties -> encoding UTF-8
    Then I make a copy of the .java file, rename it to html and open it with IE sure enough
    the Chinise is allready unreadable (not it's still readable in the IDE);
    When I compile the file with F9 I get the following error:
    whatever.java:101: warning: unmappable character for encoding Cp1252
    Tried to set the encoding to UNICODE but then the file doesn't compile.
    I gues you have to download the Japanese version for it to work correctly.

  • Thread Dump issue with LD_ASSUME_KERNEL=2.4.1

    Hi ,
    When I take Thread Dump using 'jstack <PID>' in JDK 1.5 it givss me "sun.jvm.hotspot.debugger.DebuggerException" in the dump nothing more
    I set LD_ASSUME_KERNEL=2.4.1 in my server to avaoid some other issue ( JVM crash some times)
    Surprisingly, I can not stop my server ( my java process ) after that using our Shutdow scripts , Ctrl C or even "kill -9 <PID>",
    I have to restart the machine or manually release uncleaned resources that my server occupied and restart the server
    This happens Redhar 9 as well as in Linux ES.
    Anybody faced similar problem?
    Any help or information regarding this is highly apprecialted
    Vasu
    Thread Dump Output:
    Caused by: sun.jvm.hotspot.debugger.DebuggerException: get_thread_regs failed for a lwp
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.getThreadIntegerRegisterSet0(Native Meth
    od)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$800(LinuxDebuggerLocal.java:34)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1GetThreadIntegerRegisterSetTask.doit(Li
    nuxDebuggerLocal.java:431)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(Linux
    DebuggerLocal.java:109)
    sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: get_thread_re
    gs failed for a lwp
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(L
    inuxDebuggerLocal.java:134)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.getThreadIntegerRegisterSet(LinuxDebugge
    rLocal.java:437)
    at sun.jvm.hotspot.debugger.linux.LinuxThread.getContext(LinuxThread.java:48)
    at sun.jvm.hotspot.runtime.linux_x86.LinuxX86JavaThreadPDAccess.getCurrentFrameGuess(LinuxX86
    JavaThreadPDAccess.java:75)
    at sun.jvm.hotspot.runtime.JavaThread.getCurrentFrameGuess(JavaThread.java:252)
    at sun.jvm.hotspot.runtime.JavaThread.getLastJavaVFrameDbg(JavaThread.java:211)
    at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:42)
    at sun.jvm.hotspot.tools.JStack.run(JStack.java:41)
    at sun.jvm.hotspot.tools.Tool.start(Tool.java:204)
    at sun.jvm.hotspot.tools.JStack.main(JStack.java:58)
    Caused by: sun.jvm.hotspot.debugger.DebuggerException: get_thread_regs failed for a lwp
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.getThreadIntegerRegisterSet0(Native Meth
    od)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$800(LinuxDebuggerLocal.java:34)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1GetThreadIntegerRegisterSetTask.doit(Li
    nuxDebuggerLocal.java:431)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(Linux
    DebuggerLocal.java:109)
    sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: get_thread_re
    gs failed for a lwp
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(L
    inuxDebuggerLocal.java:134)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.getThreadIntegerRegisterSet(LinuxDebugge
    rLocal.java:437)

    @brain0
    I've downloaded the glic-2.3.6 sources from gnu, so I could build it from those. I'm however reluctant to do this because I really don't want to break my install.
    I do agree with you on the NPTL statement, but pvs relies on allegro, which relies on LinuxThreads. Allegro is not being ported to new versions of glibc, so that approach is unfortunately not viable.
    @iphitus
    I wasn't very specific - it's allegro as in a lisp environment.
    I think I'll try and install an old version of arch on wmware instead. Is there anywhere you can check out glibc version numbering on old arch install isos (ie. do I need arch-0.[1-9].iso)? And anywhere you can download the old isos (tried filewatcher, but a lot of the older sites seem broken)?
    Thanks for the replies,
    Mads
    PS. I noticed that you recommended slackware for old kernels in another thread. I'm however in a bit different situation as I need old versions of glibc. Furthermore I would prefer sticking to arch, but was wondering whether there were any specific reasons for not doing that.

  • Ios 4 threaded email issue with outlook inbox?

    Anyone else have mail in their outlook inbox get removed or otherwise hidden when threading is turned on in IOS 4?
    I can see the full threaded conversation on the phone, but only the most recent message in a thread is in my outlook inbox.
    Input, solutions?

    Hi. This is a very delayed post to your original. I would like though to ask if you still have fully threaded emails in your iPhone. Since iOS 4.1 there are apparent issues, and it depends how you define 'threaded'. I am using Gmail and they have a threaded/conversations method of reading mail, very useful to see the entirety of a discussion. On my new iPhone 4 using the iPhone native mail app will not show threaded, only all of the messages from the other party, I'd need to scroll through a message to see my own input.. Or look in the Sent Mail folder. Both of which seem antiquated to me. I was interested in your post as you describe seeing your threaded mail properly on iPhone. Is this still the case?
    Thanks
    AMH.

  • Re: issue with servlet-mapping

    Hello,
    i got following url pattern on web xml and it works fine on resin, however,
    its gives me, java.lang.IllegalArgumentException: Invalid pattern,
    is there is a anyway to fix it without altering the file structure.
    <servlet-mapping>
            <servlet-name>FacesServlet</servlet-name>
            <url-pattern>/jsf/*.jsf</url-pattern>
        </servlet-mapping>

    Wildcards(*) can be used either at the beginning or end of the pattern.You cannot specify wildcards in the middle of the pattern.
    So, only either of these will work
    <servlet-mapping>
       <servlet-name>FacesServlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>Or
    <servlet-mapping>
       <servlet-name>FacesServlet</servlet-name>
       <url-pattern>/jsf/*</url-pattern>
    </servlet-mapping>

  • Are static nested classes thread-safe?

    There doesn't seem to be any definitive answer to this. Given the following code, is it thread-safe?
    public class SomeMultiThreadedWebController {
    public HttpServletResponse someMethodToExecuteViaWebRequest(HttpServletRequest request) {
        simpleQueryBuilder("SELECT...").addParameter("asdf","asdf").createQuery(EMF.getEntityManager()).executeUpdate();
    protected static class SimpleQueryBuilder {
             private String queryString;
             private Map<String, Object> params = new HashMap<String, Object>();
             public SimpleQueryBuilder(String queryString) {
                  this.queryString = queryString;
             public SimpleQueryBuilder addParameter(String name, Object value) {
                  params.put(name, value);
                  return this;
             public Query createQuery(EntityManager em) {
                  Query query = em.createQuery(queryString);
                  for (Entry<String, Object> entry : params.entrySet()) {
                       query.setParameter(entry.getKey(), entry.getValue());
                  return query;
        public static SimpleQueryBuilder simpleQueryBuilder(String queryString) {
             return new SimpleQueryBuilder(queryString);
    }Forget whether or not someone would do this, as this is just an example. I'm really trying to get at whether or not the instance variables inside the static nested class are thread-safe. Thanks for any responses.

    Hello,
    I believe you understand what you're talking about, but you state it in a way that is very confusing for others.
    Let me correct this (essentially, incorrect uses of the terminology):
    I agree that thread-safe or not is for an operation, for a member, it has some sort of contextual confusion.
    Member has a much broader meaning in the [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4] . Even "class member" applies to both an attribute, a method, or an inner class or interface.
    I think you mean "member variable" of a class (aka "attribute" or "field"). By the way, static or not is irrelevant to the rest of the discussion.
    For an operation or a member, if there's only one thread could access it atomically in one moment, we could call it thread-safe.Mmm. I was tempted to say yes (I'm reluctant to commit myself). With an emphasis on "_The encapsulating class_ makes this member's usage thread-safe".
    Still, just synchronizing each operation on a member is not enough to make all usages "thread-safe":
    Consider a java.util.Vector: each add/get is synchronized, so it is atomic, fine.
    However if one thread adds several values, let's say 3, one by one, to a vector that initially contains 0 values, and another thread reads the vector's size() (another properly synchronized method), the reader thread may witness a size anywhere among 0, 1, 2, 3, which, depending on the business logic, may be a severely inconsistent state.
    The client code would have to make extra work (e.g. synchronizing on the vector's reference before the 3 adds) to guarantee that the usage is thread-safe.
    Thus any synchronized method(With the limit stated above)
    or immutable member (like primitive type) are thread-safe.
    Additionally for a member, if it's immutable, then it's thread-safe. You mean, immutable primitive type, or immutable object. As stated previously, an immutable reference to a mutable object isn't thread-safe.
    a static final HashMap still have thread-safe issue in practice because it's not a primitive.The underlined part is incorrect. A primitive may have thread-safety issues (unless it's immutable), and an object may not have such issues, depending on a number of factors.
    The put, get methods, which will be invoked probably, are not thread-safe although the reference to map is.Yes. And even if the put/get methods were synchronized, the client code could see consistency issues in a concurrent scenario, as demonstrated above.
    Additional considerations:
    1) read/write of primitive types are not necessarily atomic: section [ §17.7 of the JLS|http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7] explicitly states that writing a long or double value (2 32-bits words) may not be atomic, and may be subject to consistency issues in a concurrent scenario.
    2) The Java Memory Model explicitly allows non-synchronized operations on non-volatile fields to be implemented in a "thread-unsafe" way by the JVM. Leading way to a lot of unintuitive problems such as the "Double-Checked Locking idiom is broken". Don't make clever guess on code execution path unless you properly synchronize access to variables across threads.
    Edited by: jduprez on Mar 4, 2010 9:53 AM

  • Issue with Generate Create Script in new ODT 11.1.0.6.10 beta

    I've tried this on several tables in my database. I choose Generate Script to ... a file, for a given table it gives me the error message "An error occurred while writing to fil: \nValue was either too large or too smal for an Int32."
    (It doesn't matter if I'm in a Oracle database project or some other project.)
    Trying to Generate Script To Project... when I'm in a Oracle Database Project, Visual Studio (2005) crashes. It appears to be some overflow exception according to crashinfo:
    EventType : clr20r3 P1 : devenv.exe P2 : 8.0.50727.762 P3 : 45716759
    P4 : mscorlib P5 : 2.0.0.0 P6 : 461eee3d P7 : 407b P8 : a3
    P9 : system.overflowexception
    (With ODT 11.1.0.5.10 beta it worked fine dispite the issue discussed in thread: Re: Issue with Generate Create Script in new ODT 11.1.0.5.10 beta
    /Tomas

    Tried to debug this error and got these exception details. Hope it helps!
    /Tomas
    System.OverflowException was unhandled
    Message="Value was either too large or too small for an Int32."
    Source="mscorlib"
    StackTrace:
    Server stack trace:
    at System.Decimal.ToInt32(Decimal d)
    at System.Decimal.op_Explicit(Decimal value)
    at Oracle.Management.Omo.TableSpaceQuotaDetails.FillTableSpaceQuota(OracleDataReader reader)
    at Oracle.Management.Omo.User.FillTableSpaceQuotas(OracleDataReader reader)
    at Oracle.Management.Omo.Connection.GetUserCollection(Boolean refresh)
    at Oracle.Management.Omo.Connection.GetUsers(Boolean refresh)
    at Oracle.Management.Omo.TableSQLGenerator.GetCreateSQLs(OmoObject obj, ArrayList& typeAndNames, Boolean checkRequired, Boolean appendSchemaName)
    at Oracle.Management.Omo.TableViewBase.GetCreateSQLs(Boolean appendSchemaName)
    at Oracle.VsDevTools.OracleUILDBProjectServices.GenerateCreateScript(OracleUILConnCtx connCtx, String[] objectNames, String objectOwner, OracleUILObjectType objectType)
    at Oracle.VsDevTools.OracleUILDBProjectServices.GenerateCreateScriptAsyncMethod(IntPtr ppvObj, OracleUILConnCtx connCtx, String[] objectNames, String objectOwner, OracleUILObjectType objectType, ICollection& scriptText)
    at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
    at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
    at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
    Exception rethrown at [0]:
    at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
    at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
    at Oracle.VsDevTools.OracleUILDBProjectServices.GenerateScriptAsyncMethodDelegate.EndInvoke(ICollection& scriptText, IAsyncResult result)
    at Oracle.VsDevTools.OracleUILDBProjectServices.OnGenerateScriptAsyncCompletion(IAsyncResult ar)
    at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
    at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
    at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
    at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)

  • Thread safe do-all class

    Hi,
    I'm new to Java programming and I've read through the forums and the numerous technical documents Sun has provided on how to make a GUI thread-safe. With what I've been able to understand, I created some template classes to handle the proper creation of JFrames, so I don't have to worry about playing with threads all the time. (I am operating under the assumption that invokeLater should handle the creation of all frames, not just the first window of the application).
    Since I'm not completely confident I've grasped the point, I was wondering if someone could look at this code to see if I've got the right idea. Your help would be much appreciated.
    Test.java
    import frames.*;
    public class Test
         public static void main(String args[])
              FrameOptions frameOpts = new FrameOptions("Options Window", 300, 400, true);
    frames\FrameOptions.java
    package frames;
    public class FrameOptions extends FrameTemplate
         public FrameOptions(String title, int width, int height, final boolean visible)
              super(title, width, height);
              javax.swing.SwingUtilities.invokeLater     (     new Runnable()
                                                 public void run()
                                                      createAndShow(visible);
         public void createAndShow(boolean visible)
              //Add all Swing components here.
              finishCreateAndShow(visible);
    frames\FrameTemplate.java
    package frames;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    public class FrameTemplate extends JFrame
         public FrameTemplate(String title)
              super(title);
         public FrameTemplate(String title, int width, int height)
              super(title);
              doSize(width, height);
         private void doSize(int width, int height)
              Dimension d = new Dimension(width, height);
              setMinimumSize(d);
              setPreferredSize(d);
         protected void finishCreateAndShow(boolean visible)
              pack();
              setVisible(visible);
    }

    OK, makes sense now.
    For anyone else who may be new and wondering about this, this can be summed up as follows.
    Summary 1:
    If you create new frames from things such as menu events, you do not need to use invokeLater. Events are automatically done in the GUI thread/event dispatching thread. But if you're spawning these things from main() (or anything else not running in the EDT), you do.
    If you're ever unsure of which thread a block of code is running in, just drop a System.out.println(javax.swing.SwingUtilities.isEventDispatchThread()); into it.
    Summary 2:
    Don't use those classes I wrote. They're rather pointless unless you're spawning all of your frames from main, which I suspect most people would not be doing.
    Thanks for the clarification.
    public static void main(String args[])
    is run in a separate thread (separate from the GUi
    i thread). So if you need to do painting or other
    swing stuff from inside the main method, just use an
    invoke later. If you create a new frame from the GUI
    thread, you don't need to invoke later. Only if you
    do it from the main method (or some other non-GUI
    thread). Hope that helps

  • Issue with calling procedure remotely

    Hello,
    Within the stored procedure, I am calling a procedure remotely but the '@v_remote_db' variable does not resolve:
    begin
    for i in cur_database_list loop
    v_remote_db := i.database_name;
    p_trunc_remote_table@v_remote_db; <<<------does not resolve
    end loop;
    end;
    Would work if obsolute value:
    p_trunc_remote_table@dev_db <------"works because dev_db is an actually database name and not a variable."
    The database link is correctly defined and works.
    Question: How to go around using obsolute value? I need to use a variable because the variable v__remote_db resolves to about 50 databases. Thank you.

    Duplicate thread:
    Re: issue with remote procedure calls
    Amiel

  • Starting issues with iMac 27 i5 quad after crucial RAM expansion

    I have read through a few threads regarding issues with crucial RAM upgrades in iMacs but they don't quite match what I am experiencing.
    I have installed 2 x 2 GB Crucial RAM (manufacturer 0x80CE) in addition to the pre-installed 4GB. The iMac works fine without any glitches, freezes or crashes. However, when I try to start it up in the morning I can hear the HD starting up and stopping once. The start chime doesn't sound and the display stays black. I take out the 4GB and the computer starts up without any problems. I then switch it off again, install the other 2 RAM again and lo and behold: all works fine. Until the next morning. I do not entirely disconnect the iMac, which is an Apple refurbished machine, I just switch it off.
    The first time that happened, I thought it was another problem like USB, bluetooth etc. So I systematically disconnected and reconnected all peripherals, I even used a USB mouse and keyboard and tried to start up from the restore DVD. So I went through all that pain.
    If there is an existing thread I would appreciate if you could point me in the right direction because I couldn't find anything like this on this forum.

    Did you test all 4 modules one at time in a top slot as suggested, to see if they are all working?
    ● If any one of the modules fail to properly boot the iMac, factory or crucial then do not reinstall it into the iMac.
    ● If all of the modules individually boot the iMac, then try reinstalling the Crucial in the top slots, the factory in the bottom slots and Startup the iMac reseting the PRAM.
    http://support.apple.com/kb/HT1379
    +1. Locate the following keys on the keyboard: Command, Option, P, and R. You will need to hold these keys down simultaneously in step 4.+
    +2. Turn on the computer.+
    +3. Press and hold the Command-Option-P-R keys. You must press this key combination before the gray screen appears.+
    +4. Hold the keys down until the computer restarts and you hear the startup sound for the second time.+
    +5. Release the keys.+
    Now then if the iMac is not booting from all 8GB of RAM, then there is a compatibility problem with the Crucial RAM and you need to contact Crucial and tell them that there Ram is not working with your Factory RAM.
    Why would you only want RAM in the bottom slots, I thought the idea here was to upgrade from 4 to 8GB?
    The article clearly states that the iMac will not boot with only 1 module in a bottom slot.
    http://support.apple.com/kb/HT3918

  • Question about EJB and thread safe coding - asking again!

    sorry everyone, no one seems to be interested in helping me on this, so i post it again.
    i have a question about the EJB and thread safe coding. when we build EJBs, do we need to worry about thread safe issue? i know that EJBs are single threaded, and the container manages the thread for us. maybe i am wrong about this. if i wasnot, how can we program the EJB so that two or more instance of EJB are not going to have deadlock problem when accessing data resources. do we need to put syncronization in ours beans, do we even need to worry about creating a thread safe EJB? thanks in advance. the question really bothers me a lot lately.

    sorry everyone, no one seems to be interested in
    helping me on this, so i post it again.Excellent plan. Why not search a little bit on your own instead of waiting for your personal forum slaves to answer your call. See below.
    i have a question about the EJB and thread safe
    coding. when we build EJBs, do we need to worry about
    thread safe issue? Read this: http://forum.java.sun.com/thread.jsp?forum=13&thread=562598&tstart=75&trange=15
    i know that EJBs are single
    threaded, and the container manages the thread for us.
    maybe i am wrong about this. if i wasnot, how can we
    program the EJB so that two or more instance of EJB
    are not going to have deadlock problem when accessing
    data resources. do we need to put syncronization in
    ours beans, do we even need to worry about creating a
    thread safe EJB? thanks in advance. the question
    really bothers me a lot lately.
    Java's Thread Tutorial
    JavaWorld: Introduction to Java threads
    IBM: Introduction to Java threads
    Google: java+threads+tutorial

  • Our software vendor tells to use FF 3.5.1. because of some printer issues with their web based program. How safe is it to work with FF 3.5.1 in 2012?

    Our software vendor tells to use FF 3.5.1. because of some printer issues with their web based program. How safe is it to work with FF 3.5.1 in 2012?

    Thanks for the reply. I'll have a look at your solution.

Maybe you are looking for

  • Not able to create function in ALBPM Studio 6.0

    Hi, I am trying to write a method that returns a string. But i keep on getting an error which says that return statement can only be present in functions. Now I tried all possible ways but i was not able to create a function. Could anyone please help

  • Watching dvd's on TV from powerbook

    I was wondering how to connect my powerbook on my vcr or tv to watch a dvd or photos on my tv. I have tryed using Svid to Svid but not sure how to send a signal out. Any help would be helpful. thanks

  • Adobe Air on iMac G5  Intel Core Duo 2133

    I have just tried to download an update to Adobe Air and been notified that the updates will no longer work on my iMac. This is the quote from their web site : Adobe will be discontinuing support of PowerPC-based computers and the Windows 2000 operat

  • Oracle Sales Contract Understanding

    Dear All Kindly someone explain me the key functionality of oracle sales contract. As Balanket Sales agreement option already avaiilable in order management, is sales contract module function is just to link/ input contract clauses with it??? Kindly

  • Process Chain Attribute Change Run

    Hi Experts, I am working BI 7.0 version, I am try to run Process chain showing warning Error in Infopackage level, Please find the below Error Message: A type "Attribute Change Run" process has to follow process "Execute InfoPackage"  var.ZPAK_4DLO5G