Scope of Threads

Does anyone know. I want to have users be able to enter commands into a text field, and then have the text field action listener create a new thread to handle the command (because some commands are really long). My question is, after I start the newly created thread, and then return from the actionPerformed method, the newly created thread will no longer have any references pointing to it because it will have gone out of scope, so does that mean that the thread might be garbage collected while it is still running? Here is how My action listener works. Thank you.
inputField.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e)
                    JTextField field = (JTextField)e.getSource(); //safe cast
                    String command = field.getText();
                    field.setText("");
                    UserCommandThread userCommandThread = new UserCommandThread(infoSocket, command, console);
                    userCommandThread.start();
          });

Actually, when a Thread is started, the instance is registered to "ThreadGroup".
ThreadGroup holds this reference until the thread exits, i.e. until the run() method exits.

Similar Messages

  • OnApplicationEnd() - are all server resources available?

    Hi all
    I need to use onApplicationEnd() as part of Application.cfc to execute a call on a 3rd party Java object to close a connection to another device on the network.
    The code I have worked perfectly if I call it as a normal request, but when I place it in the onApplicationEnd() method I'm running into some errors. These errors suggest that CF might in fact be shutting down already to the point where I cannot access these 3rd party Java classes. Not good, but also unexpected.
    I then decided I'd create a parallel thread in the onApplicationEnd() and then rejoin to the main thread when I had closed by connection, but I get an obscure null pointer exception trying to create this thread from this function. Again, the same code works well if I use it in a normal request.
    Is there restrictions to what I can do in onApplicationEnd() and if so is there any work around?
    I am using CF 8 (8,0,1,195765) Developer Edition on a Windows XP machine.
    Many thanks in advance!
    Ciaran Archer

    Thanks for the replies so far. Here is the code:
    <cffunction name="onApplicationEnd" returnType="void">
            <cfargument name="appScope" required="true" />
            <cfset var logLocation = "test" />
            <cflog file="#logLocation#" text="*** [Application.cfc]  - **** START RUN ****" />
            <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - onApplicationEnd() called " />
            <cftry>
                    <cfif structKeyExists(ARGUMENTS, "appScope")>
                            <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - ARGUMENTS.appScope is defined" />
                    <cfelse>
                            <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - ARGUMENTS.appScope is undefined! " />
                    </cfif>
                    <!--- Check if we have a test crypto object in scope, and if so close it's connection --->
                    <cfif structKeyExists(ARGUMENTS.appScope, "testCrypto")>
                            <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - onApplicationEnd() - crypto object exists in app scope" />
                            <cfset ARGUMENTS.appScope.testCrypto.closeConnection() />
                            <<cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - onApplicationEnd() - closed crypto server connection" />
                    <cfelse>
                            <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - onApplicationEnd() - NO crypto server connection present to close" />
                    </cfif>
                            <cfcatch type="any">
                                    <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - onApplicationEnd() - Error - #cfcatch.message#" />
                            </cfcatch>
                    </cftry>
            <cflog file="#logLocation#" text="*** [Application.cfc]  - #timeformat(now(),'HH:mm:ss' )# - onApplicationEnd() ended " />
    </cffunction>
    The line to close the connection on my object is failing with the message: 'java.lang.IllegalStateException: Shutdown in progress'.
    Here are the full logs for one run:
    "Information","Thread-8","10/23/09","09:05:54",,"*** [Application.cfc]  - **** START RUN
    "Information","Thread-8","10/23/09","09:05:54",,"*** [Application.cfc]  - 09:05:54 - onApplicationEnd() called "
    "Information","Thread-8","10/23/09","09:05:54",,"*** [Application.cfc]  - 09:05:54 - ARGUMENTS.appScope is defined"
    "Information","Thread-8","10/23/09","09:05:54",,"*** [Application.cfc]  - 09:05:54 - onApplicationEnd() - crypto object exists in app scope"
    "Information","Thread-8","10/23/09","09:05:54",,"*** [Application.cfc]  - 09:05:54 - onApplicationEnd() - Error - Shutdown in progress"
    "Information","Thread-8","10/23/09","09:05:55",,"*** [Application.cfc]  - 09:05:55 - onApplicationEnd() ended "
    I really hope there is a work-around. The same issue occurs when I run CF as a console window and stop it with CTRL-C or if I run cfstop.
    Cheers,
    Ciaran

  • Method Scope variables controls Multi-Threading !

    Hye there Experts !
    First, let me thank you all for such a brain-stuff sharing around; feel nice to be a part here.
    While browsing through the below article, found something confusing...kindly clarify.
    http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html?page=1
    Extract from the above discussion I understand :
    when a variable is moved to method scope instead of instance scope, synchronization is achieved.
    How is this true for servlets ???
    Method scope variables are available only during method call I think...here, since this is a servlet, there will be only one instance and if many (lets say 10) requests hits this servlet object, all these threads will read same counter as all of them enter into this only one method of this object,
    so...this should be still not thread safe I guess.
    I didn't want to execute and see results of this code, but I am trying to understand the key at first.
    Please guide me before brain blows... :-)
    Would also appreciate any references that really says true things about
    'synchronization for enterprize (handle huge requests) web apps - technques for servlets and any other stuff'
    Thanks again guys, have a wonderful time.

    feel nice to be a part here.Welcome to the mad-house ;-)
    Method scope variables are available only during method callWARNING: I'm no guru, so this may be misleading or just plain wrong.. but as I understand it:
    Yep a "local" variable exists only the context of the execution of it's containing method... so a local variable is implicitly bound to the thread that created it (by invoking the method in which the local is declared)... a local variable can't be accessed directly by another thread simply because the other thread has no access-path to the variable (you can't expose a local through getters & setters)... hence locals are thread safe.
    The important bit is that it's the thread which "owns" the local variable... not the declaring method... if the method is executed concurrently by two threads, each thread will have its own private copy of all the local variables.
    One other question though: are locals in static methods still thread safe? I'm not sure.
    package forums;
    class NonfinalLocalVariableInThreadTest
      public static void main(String[] args) {
        try {
          new Thread(new Runnable() {
            public void run() {
              System.out.println(args[0]);
          }).start();
        } catch (Exception e) {
          e.printStackTrace();
    compiler error
    C:\Java\home\src\forums>"C:\Program Files\Java\jdk1.6.0_07\bin\javac.exe" -Xlint -d c:\java\home\classes -cp c:\java\home\src;.;c:\java\home\classes c:\java\home\src\forums\NonfinalLocalVariableInThreadTest.java
    C:\Java\home\src\forums\NonfinalLocalVariableInThreadTest.java:9: local variable args is accessed from within inner class; needs to be declared final
              System.out.println(args[0]);
                                 ^
    1 error
    Output completed (0 sec consumed)

  • [JCoAPI] The context with the session id scope type [null] is currently used in thread HTTP Worker

    Hello to all SAP-experts.
    I have an error in SAP CE, and i can see in troubleshooting following information:
    [JCoAPI] The context with the session id [JCo_mMnig6B1YRWfNCWhW0pY0CgFOhzFTAHqyFEA_SAP:P3fshVcB4PLh3CzLBVbpf5lVRxzFTAHqyFEA_SAPyxuggqvaUEsNVbxNQybjvxH0] scope type [null] is currently used in thread HTTP Worker [@1902361406] [0x91].Current thread is HTTP Worker [@1590998042] [0x97].
    invoked at com.sap.conn.jco.rt.Context.checkBusy(Context.java:633)
    invoked at com.sap.conn.jco.rt.Context.getConnection(Context.java:153)
    invoked at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:1466)
    invoked at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:1437)
    invoked at com.sap.conn.jco.rt.AbapFunction.execute(AbapFunction.java:300)
    invoked at com.sap.conn.jco.rt.DefaultRequest.execute(DefaultRequest.java:68)
    invoked at com.sap.tc.cm.arfc2.model.ARFC2GenericModelClassExecutable.executeInternal(ARFC2GenericModelClassExecutable.java:107)
    invoked at com.sap.tc.cm.arfc2.model.ARFC2GenericModelClassExecutable.execute(ARFC2GenericModelClassExecutable.java:68)
    invoked at com.sap.tc.cm.arfc2.gci.ARFC2TypedModelClassExecutable.execute(ARFC2TypedModelClassExecutable.java:54)
    invoked at ru.sng.terminal.utt.terminals.wd.comp.utt_term.Utt_term.loadReasonsToStop(Utt_term.java:1542)
    invoked at ru.sng.terminal.utt.terminals.wd.comp.utt_term.Utt_term.wdDoInit(Utt_term.java:186)
    invoked at ru.sng.terminal.utt.terminals.wd.comp.utt_term.wdp.InternalUtt_term.wdDoInit(InternalUtt_term.java:1054)
    invoked at com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.doInit(DelegatingComponent.java:161)
    invoked at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:227)
    invoked at com.sap.tc.webdynpro.progmodel.components.Component.initController(Component.java:258)
    invoked at com.sap.tc.webdynpro.progmodel.controller.Controller.init(Controller.java:206)
    invoked at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.init(ClientApplication.java:590)
    invoked at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.doPreprocessing(ClientApplication.java:1457)
    invoked at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doPreprocessing(ApplicationSession.java:660)
    invoked at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:349)
    invoked at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:326)
    invoked at com.sap.tc.webdynpro.serverimpl.core.AbstractDispatcherServlet.doContent(AbstractDispatcherServlet.java:87)
    invoked at com.sap.tc.webdynpro.serverimpl.wdc.DispatcherServlet.doContent(DispatcherServlet.java:89)
    invoked at com.sap.tc.webdynpro.serverimpl.core.AbstractDispatcherServlet.doGet(AbstractDispatcherServlet.java:55)
    invoked at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    invoked at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    invoked at com.sap.engine.services.servlets_jsp.server.Invokable.invoke(Invokable.java:152)
    invoked at com.sap.engine.services.servlets_jsp.server.Invokable.invoke(Invokable.java:38)
    invoked at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:457)
    invoked at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:210)
    invoked at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:441)
    invoked at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:430)
    invoked at com.sap.engine.services.servlets_jsp.filters.DSRWebContainerFilter.process(DSRWebContainerFilter.java:38)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.servlets_jsp.filters.ServletSelector.process(ServletSelector.java:81)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.servlets_jsp.filters.ApplicationSelector.process(ApplicationSelector.java:278)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.WebContainerInvoker.process(WebContainerInvoker.java:81)
    invoked at com.sap.engine.services.httpserver.chain.HostFilter.process(HostFilter.java:9)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.ResponseLogWriter.process(ResponseLogWriter.java:60)
    invoked at com.sap.engine.services.httpserver.chain.HostFilter.process(HostFilter.java:9)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.DefineHostFilter.process(DefineHostFilter.java:27)
    invoked at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.MonitoringFilter.process(MonitoringFilter.java:29)
    invoked at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.SessionSizeFilter.process(SessionSizeFilter.java:26)
    invoked at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.MemoryStatisticFilter.process(MemoryStatisticFilter.java:57)
    invoked at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.filters.DSRHttpFilter.process(DSRHttpFilter.java:43)
    invoked at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)
    invoked at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)
    invoked at com.sap.engine.services.httpserver.server.Processor.chainedRequest(Processor.java:475)
    invoked at com.sap.engine.services.httpserver.server.Processor$FCAProcessorThread.process(Processor.java:269)
    invoked at com.sap.engine.services.httpserver.server.rcm.RequestProcessorThread.run(RequestProcessorThread.java:56)
    invoked at com.sap.engine.core.thread.execution.Executable.run(Executable.java:122)
    invoked at com.sap.engine.core.thread.execution.Executable.run(Executable.java:101)
    invoked at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:328)
    Please, tell how can i solve this problem ?

    Hi Konstantin,
    it has nothing to do with the number of system threads. You are obviously executing several function modules statefully in multiple threads within the same session context. Stateful requests can only be executed in an ordered manner in case they should belong together. You are using ARFC2, which is part of the WebDynpro runtime. In case you are sure that the calls are independent from each other, it might be a good idea to adjust the scope type of some of your bindings. Then the requests will be executed with different scopes depending on your configuration and you can execute them concurrently
    Best regards,
    Markus

  • Threads & Scope

    I'm trying to write a multi-threaded program where each Thread quite expectedly are performing their own separate tasks. However, I'm not sure of if I'm implementing them in the correct way in order to do my bidding.
    Usually, I have a main thread (the class whose public static void main() is run) and then create instances of another class that extend Thread and call them to start. I.E.:
    The main class whose main() is run:
    public class TheMainClass
        ThreadedClass secondThread = new ThreadedClass();
        ThreadedClass thirdThread = new ThreadedClass();
        public static void main(String args[])
            // Start the second and third threads
            secondThread = new ThreadedClass();
            thirdThread = new ThreadedClass();
            secondThread.start();
            thirdThread.start();
            // Assign Threads tasks
            // This is the part I'm not sure that is correctly implemented
            secondThread.makeConnection();
            thirdThread.makeConnection();
    }The second class that extends Thread:
    public class ThreadedClass extends Thread implements Runnable
        public void run()
            // Code to run when started
       public void makeConnection()
            // Code to connect to a pre-defined socket
    }The goal in this specific example is to create two threads and assign each to run their makeConnection() method. Lets assume that this method connects to a server based on a set values unqiue to each instance of ThreadedClass.
    What I would like it do:
    - Create two threads
    - Each thread object calls their own makeConnection() method simultaneuosly and establish connections to their respective servers.
    What I'm afraid it will do:
    - I'm afraid that calling the methods in each of these thread objects from the scope of the main thread instead of calling of from within the scope of each thread (i.e. their respective run() methods) will only result in the main thread executing each call makeConnection() one at a time, leaving the instances of ThreadedClass to sit idle.
    So it boils down to: how do I control assign each thread methods to execute properly?

    Ok, I guess generalizing my question isn't working. I'll try to apply it to what I'm really working on.
    I'm writing a server browser of sorts; a window with a list of a bunch of servers that you can connect to. In this application, I want the browser to send short queries to the server to request basic info, like it's name, number of clients connected, etc...
    Where my question about threads and scope comes in is with these queries. When the user presses the button to "refresh all" I don't want the server browser to go down the list one by one, waiting 10 seconds for each to timeout if it can't connect. That'd take forever. Instead, I want it to make a thread for each server to make the connections and update the info on the screen accordingly.
    So, I have a class called Connection, which is a thread. One instance of Connection is assigned each server. Then, at any point, I want to be able to call a method inside each instance of Connection called query(). The problem is, if I call this method with say, connection1.query(), it's going to execute in my main scope and do updates one by one...
    So, how do I get a thread to execute something in its own scope from the scope of the main thread? The only way I've managed to do this is by setting boolean variables in the instance of Connection to control what it does, but this gets horribly sloppy very quickly. Is there a better, cleaner way to do this such as calling it like a method?
    EDIT:
    The previous reply contains a perfect example of how I've been working around by using booleans to call my methods. However, I'm looking for a cleaner, neater solution.

  • How to dynamically load jar files - limiting scope to that thread

    Dynamically loading jar files has been discussed a lot. I have read a quite a few posts, articles, and demo code for doing just that. However, I have yet to find a solution to my problem. Most people modify their system class loader and are happy. I have done that and was happy for a time. Occasionally, you will see reference to an application server or tomcat or some other large project that have successfully been able to load and unload jar files, allow for dynamic deployment of code, etc. However, I have not been able to achieve similar success; And my problem is much less complicated.
    I have an application that executes a thread to send a given file/message to a standard JMS Server Queue. Depending on the parameters selected by the user, this thread may need to communicate with one of a number of JMS Servers, ie. JBoss, WebLogic, EAServer, Glassfish, etc. All of which can be done with the same code, but each needs to load their own flavor of JMS Client Jar files. In this instance, spawning a separate JVM for each communication would work from a classloader perspective. However, I need to keep it in the family and run under the same JVM, albeit each JMS Server Connection will be created and maintained in separate Threads.
    I am close, I am doing the following...
    1. Creating a new URLClassLoader in the run() method of each thread.
    2. Set this threads contextClassLoader to the new URLClassLoader.
    3. Load the javax.jms.JMSException class with the URLClassLoader.loadClass() method.
    4. Create an initialContext object within this thread.
    Note: I read that the initialContext and subsequent conext lookup calls would use the Thread�s
    contextClassLoader for finding/loading classes.
    5. Perform context.lookup calls for a connectionFactory and Queue name.
    6. Create JMS Connection, etc. Send Message.
    Most of this seems to work. However, I am still getting a NoClassDefFoundError exception for the javax.jms.JMSException class ( Note step #3 - tried to cure unsuccessfully).
    If I include one of the JMS Client jar files ( ie wljmsclient.jar for weblogic ) in the classpath then it works for all the different JMS Servers, but I do not have confidence that each of the providers implemented these classes that now resolve the same way. It may work for now, but, I believe I am just lucky.
    Can anyone shine some light on this for me and all the others who have wanted to dynamically load classes/jar files on a per Thread basis?

    Thanks to everyone - I got it working!
    First, BenSchulz' s dumpClassLoader() method helped me to visualize the classLoader hierarchy. I am still not completely sure I understand why my initial class was always found by the systemClassLoader, but knowning that - was the step I needed to find the solution.
    Second, kdgregory suggested that I use a "glue class". I thought that I already was using a "glue class" because I did not have any JMSClient specific classes exposed to the rest of the application. They were all handled by my QueueAdmin class. However...
    The real problem turned out to be that my two isolating classes (the parent "MessageSender", and the child "QueueAdmin") were contained within the same jar file that was included in the classpath. This meant that no matter what I did the classes were loaded by the systemClassLoader. Isolating them in classes was just the first step. I had to remove them from my jar file and create another jar file just for those JMSClient specific classes. Then this jar file was only included int custom classLoader that I created when I wanted to instantiate a JMSClient session.
    I had to create an interface in the primary jar file that could be loaded by the systemClassLoader to provide the stubs for the individual methods that I needed to call in the MessageSender/QueueAdmin Classes. These JMSClient specific classes had to implement the interface so as to provide a relationship between the systemClassLoader classes and the custom classLoader classes.
    Finally, when I loaded and instantiated the JMSClient specific classes with the custom classLoader I had to cast them to the interface class in order to make the method calls necessary to send the messages to the individual JMS Servers.
    psuedu code/concept ....
    Primary Jar File   -  Included in ClassPath                                                      
    Class<?> cls = ClassLoader.loadClass( "JMSClient.MessageSender" )
    JMSClientInterface jmsClient = (JMSClientInterface) cls.newInstance()                            
    jmsClient.sendMessage()                                                                      
    JMSClient Jar File  -  Loaded by Custom ClassLoader Only
    MessageSender impliments Primary.JMSClientInterface{
        sendMessage() {
            Class<?> cls=ClassLoader.loadClass( "JMSClient.QueueAdmin" )
            QueueAdmin queueAdmin=(QueueAdmin) cls.newInstance()
            queueAdmin.JMSClientSpecificMethod()
        }

  • How to make a global scope component to be thread safe?

    One of my global component preserves states in its member variables, I am afraid that it's might messed up in multi-threading conditions, so how to make a nucleus global component to be thread safe?
    Edited by: user13344577 on Jul 14, 2011 9:45 AM

    Hi,
    Just to help integrate Shaik's and my own seemingly contradictory replies:
    If the member variables in your global component actually need to be globally available, so that multiple threads/sessions need to seem the same data, then you need to use synchronization or some scheme to make this data thread-safe when updating it. If the member variables are non-global data and are simply for convenience of having data available for multiple method calls or something like that, then you should do as I said (don't use synchronization) and use one of my suggestions to avoid this.
    I have seen customers frequently do what I replied about and store non-global data in a global component, and Shaik simply interpreted what "user13344577" is trying to do differently. Clarification is needed to know which of our answers better applies.
    Thanks.
    Nick Glover
    Oracle Support for ATG Products

  • Why Multiple users share the same Thread

    Hello
    <BR>
    I am developing a small application which You can like a forum
    <BR>
    When mulitiple users put their questions.I use jsp and servlets.
    <BR>
    when i open two windows of the browser then no separate question is
    present all the windows put the same question again and again with
    the same user name although i login with different names and has
    put question on different forums.
    i use session tracking for this purpose and has scope session.
    i change scope to request but nothing.
    i put all information of user name and thread in the session.setAttribute("key",value)
    and get it by using getAttribut("key") where i need it.
    <BR>
    My question is how i can solve this problem.
    In forums like jguru or sun or anyother how they maintain individual
    data for each person.
    please reply me soon as i am getting too late bcz of this problem
    ThanX

    For changing container, I mean to add a context to the new container for your application. With a little eyeballing, you can find where to add Context element in server.xml[in conf folder for Tomcat]. You need to change the bold ones.
    <Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="true" debug="5" docBase="e:/DBTest" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/DBTest" privileged="false" reloadable="true" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
    <Logger className="org.apache.catalina.logger.FileLogger" debug="0" directory="logs" prefix="localhost_DBTest_log." suffix=".txt" timestamp="true" verbosity="1"/>
    </Context>
    I think u got rid of the problem.
    Hafizur Rahman
    SCJP

  • Logging Java objects and threads. Application sampling.

    I am using a laptop to run my application on. It uses windows XP and it is the only application running on that machine. I use TCP and serial port to communicate to other devices. My application is supposed to use up to 300M of memory but apparently it using much more than that. The laptop physical memory size is 512M. I am wondering if there is a way to sample my application periodically. What I mean by that is, after the applications runs I want to run at the same time kind of profiler that every, let us say, 10 minutes logs the number of objects created and what those objects are or what the current ones are. The number of threads running and what are their names. I want to know what is using all of this memory. The memory usage goes up to about 420M. As a result, the application throws out of memory exception. I believe I can get the number of threads running but do not know how to get their names. I need to know all of that so I would go into my code and see where it is happening and try to solve the problem. One of the ways I have in my mind now is to put a print out everywhere I create an object or thread, but that�s very expensive. Any hints or tips could be useful.
    Thank you in advance.
    P.S.:
    I do not want to run a profiler such as JProfiler because the application is running live and I do not have access to it. I want to embed these logs into the application itself and rerun it on a live system.

    As a first thought, I'm guessing that you're merely thinking that your program will not exceed 300 megabytes just based on the -Xmx300M command you may be passing your program. This is a max heap size, not the max footprint your program will take. Be aware that this can go beyond the scope of 300 MB....
    Now, if you want very detailed information about processes, memory usage, etc, you might be able to keep track of it yourself, but if you want this information from a system-level sort of thing you will not get it, as one of the major points of Java is that it does not care about a lot of system specifics.
    Now, if you're really interested in keeping track of threads, I don't see why you could not just write to a log file every time you spawn a new thread of a particular kind.

  • Multiple JSP's accessing the same thread

    I have multiple users calling multiple JSP's. I also now want to add in a connection pool, which is implemented as a Runnable (It's a thread). However, how do I set it up so that all of the JSP's get a reference to the same connection pool?
    I have done this in a Servlet, where I could have the connection pool constructed in the init() function, and then the Servlet kept a static reference to the pool. Then for each request, I pass the reference to the pool into the service() function of my supporting classes.
    How can I do this in JSP?

    There are few things.......
    I do not know which application server you are using , but almost all competitive application server provide the concept of connection pooling. You do not have to implement connection pooling yourself. And to get a handle to the connection from the pool is through JNDI namespace(as you do for EJB.)
    Now if you still want to do that yourself then, i can propose one way.
    1) Put a instance of the Java class which holds the connection pooling in the application scope.
    ie useBean= Yourclass scope="application"
    2) Now all the JSP's will be able to get to the same object.
    So Look for documentation for putting objects in different scope ie session, application etc.
    Srinivasan Ranganathan

  • Is there an idiots guide to JSF and scope somewhere?

    I am getting very confused with scope and JSF.
    I have a page that just displays customer details (from CustomerBean extends Customer) with a button that should allow the user to change the customer details. Both pages use the same backing bean (is that recommended?).
    customerDetail.jsp --> editCustomer.jsp
    If I set the scope of CustomerBean to session, editCustomer sees the same customer as customerDetail. It seems to me that I shouldn't really be using session scope as I don't want a particular customer to hang around once I have finished with him. So what should I be doing?
    Should customerBean be request scoped? If so how does editCustomer see it?
    Or should I somehow destroy the session scoped customerBean when I have finished with it?
    I also notice that some example jsps out there have a hidden field for the ID - should I simply look up the customer again from the database in editCustomer?
    I also tried to add a <h:inputHidden value="#{customerBean}"/> but that broke my jsp.
    I have bought and read the J2EE tutorial but I am still confused as to what the recommended way to drag the same Object through two jsp pages.
    It's probably very simple but it's doing my head in ;-)
    - David

    Yeah, forming a model in your head to explain something can be painful, sometimes. This question has come up before, including where I work, and I've never really seen a comprehensive answer, so I'll just write one. :)
    This is kind of a basic servlet concept, so I'll talk mostly about servlets. JSF is just flavor on top of this.
    The lifetime of the request is: from the time the user hits "submit" until the time the response is fully rendered, whatever page that is.
    So, you have a form the user has filled out and he/she hits "submit".
    The HTTP POST request goes to the server (open port 80, write some "key: value" headers to satisfy the HTTP protocol requirements, followed by a stream of text that represents the users' form field values, wait for a response) which then proceeds to process it by parsing the incoming data and making a bunch of subroutine calls. The last set of subroutine calls basically involves a bunch of println() calls to write HTML into an output stream, which is the response the requesting browser is listening for. When that stream is done, the browser displays the html.
    There's nothing that says the html that's displayed is the same as the html that originally held the form the user submitted. The first page is essentially garbage that somehow generated some form fields. The server could care less what it was, all it wants is the key=value pairs.
    You could, if you were so inclined, code all those println()s yourself. That's straight servlet programming. It's totally under your control. You could code println( "<html><body>Hi, Mom!</body></html>"); and be done.
    Or, you could write a JSP that, when compiled, turns into essentially a subroutine chock full o' println()s, and you could call that subroutine.
    You do that with RequestDispatcher.forward(). It's just a subroutine call. (But don't do any more scribbling on the output stream after it returns, 'cause the stream's essentially been closed.)
    It's all a big call tree with one thread of execution, single entry, single exit. One of the nice things about servlets is that the infrastructure makes available to you, in a contextual sorta way, the original request parameters plus whatever attributes you choose to attach to the request as your proceed w/your processing, kind of like charms on a charm bracelet (via ServletRequest.setAttribute()). (When I say "contextual", I mean the ServletRequest is passed in as a parameter to Servlet.service() so you can sling it around in your call tree.) Attributes you choose to attach while processing incoming form data are available later (for instance... in the subroutine that has all those println()s you so carefully coded up or allowed the JSP compiler to generate for you).
    When the call tree is done (you've finally printed "</html>", marked the output stream "done" somehow and shipped all that HTML back out to the browser), the ServletRequest object that held the incoming form parameters plus whatever attribute cruft it accumulated is garbage collected. (I could write something poetic about Elysium and gamboling among daisies, but... nah.) So, the lifetime of that data associated w/the ServletRequest is the duration of that request-processing call tree.
    JSF gives you a nice bunch of automatically-generated request attributes, corresponding to your request-scoped managed beans. It even very kindly transfers (via the value bindings) incoming form parameters into properties of beans which are attributed onto your ServletRequest, automagically.
    So, if, in your JSP, you bind your form data to request-scoped bean properties (not the bean itself, but the bean's properties), those exact same bean properties will be visible on whatever JSP you eventually wind up on and it will be available to whatever intervening logic you code up ("Invoke Application" phase), and when the request is done, it all vanishes into thin air.
    To be more specific to your question: yes, I believe it is recommended to have the same bean between pages. That's kind of the whole point. If you find yourself at the end of a request trying to destroy session data that was created at the beginning of that request, you should probably be using request scoping, not session.
    I could be wrong, but I don't think you can bind an entire bean to an html element value. You bind bean properties. Of course, there's nothing to say that a bean property couldn't be... another bean!
    In your particular case, I guess you have a bunch of display-only strings that come from your customer bean, plus a hidden "key" field somewhere. You could bind that hidden field to the customer.key property and Customer.setKey() would do whatever's necessary to get the rest of the data into the bean. That could be a d/b lookup or a map or array (cache) fetch. Or you could have a "current customer" in your session (that would have to be session-scoped, because you paint the detail screen w/one request and then paint the "edit" screen w/the same customer but in a different request). That "current customer" concept might cause you some problems later when you go multi-window or multi-frame in your webapp (truuuuuuuust me).
    Also, I'm not sure why you need a CustomerBean separate from Customer. Can you just make Customer a bean and be done with it?
    Holy cow, what an essay this turned out to be.
    John Lusk.

  • No preview or scopes information in Apple Color

    This is the second time I've had this issue in around 3 months. I had initially solved the issue but had to do a full clean install of OSX and also my Final Cut Studio package. It's occured again for no apparent reason and to be honest I don't want to waste another few days doing a clean install of both my operating system and editing package again.
    The issue is, my project in FCP 7 is ready for grading and when I click 'Send To > Apple Color', it brings the project over into Color and every clip can be scrubbed through on the timeline. However there are no previews showing up of the clips in the preview window, as well as no colour information/data showing up in the scopes. It's as if there is not video within my project even though there is a good 9 or 10 minutes of footage that needs to be graded!
    I want to sort this problem as soon as possible due to this being a project that is of utmost value!
    I've attached an image of the issue to this post. Thanks in advance.

    Ladies and gents I'd just like to let you know I've solved this issue! It was a bit of a eureka moment but it seemed to do the trick. I'll explain below.
    Basically I have a short section of the film that was shot on Super 8mm film. The Telecine I had meant the footage came back as a perfect 4:3 square, but I wanted a more traditional smooth/feathered/curved/rounded frame over the footage, so I'd created a PNG file with a black border and transparent centre to overlay on top.
    For no apparent reason I decided to delete this image file and try sending the project to Color. Low and behold it's worked no problem and I can now finally see my video in the video preview section, as well as the colour data and information in the scopes.
    A massive thank you to everyone who commented on this thread! Thanks for your time.

  • How to get value from Thread Run Method

    I want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that it seems that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get Inside the run method::: But I get only Inside */
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";

    I think this is what you're looking for. I hold up main(), waiting for the results to be concatenated to the String.
    public class sampsynch
        class SampleThread extends Thread
         String x = "Inside";
         public void run() {
             x+="the run method";
             synchronized(this) {
              notify();
        public static void main(String[] args) throws InterruptedException {
         SampleThread t = new sampsynch().new SampleThread();
         t.start();
         synchronized(t) {
             t.wait();
         System.out.println(t.x);
    }

  • Locking when using a component as an object in the application scope...

    I have a component that I am building right now that hold
    application settings that are stored in a database table. The
    settings are maintained in a structure "variables.settings" within
    the component and can only be accessed by get and set methods. I
    use the following to create the instance of the object:
    <cfset application.settings =
    createObject("settings","component").init() />
    Now when getting a setting I do not think locking is needed
    as its just reading the value and I am not really concerned with a
    race condition...
    But when using the set method which will update the value of
    the setting.... should I be locking that as technically the object
    is in a shared variable scope? Or is it safe because its within the
    cfc/object?
    If locking is needed, would I need to lock when using the set
    method? or can I just build the lock into the set method so that
    its always there?

    To disagree with craigkaminsky, I think you only need to lock
    if you are
    concerned about race conditions and what could happen during
    a 'dirty
    read' and|or conflicting writes.
    A lot of developers have an old impression of ColdFusion that
    one *must*
    lock all shared scope variable access to maintain a stable
    application.
    This dates from the ColdFusion 4.5 days where there where
    bugs in
    ColdFusion that could cause memory leaks and eventual
    application
    instability if one did not lock shared scope reads and
    writes. This has
    long been fixed, but the advice persists.
    So now it is only a matter of your data and what would happen
    if one
    user read an old value while it was in the process of being
    updated by
    another user. Or could two users be updating the same value
    at the same
    time and cause conflict. If either of those two statements
    are true,
    then yes you should use locking as required by your
    application.
    But if they are both false and it does not matter that user A
    might get
    the old value microseconds before user B changes it. Or there
    is no
    concern with user A changing it once and user B changing it
    again to
    something different moments later without knowing the user A
    has already
    changed it. Then locking is probably unnecessary.
    There can be a cost to over locking shared variable writes
    and|or reads.
    Every time one creates a lock, one is single threading some
    portion of
    ones code. Depending on how the locking is done, this single
    threading
    may only apply to individual users or it may apply to every
    single user
    on the entire server. Either way, too much of this in the
    wrong places
    can create a significant bottle necks in ones application if
    too many
    user requests start piling up waiting for their turn through
    the locked
    block of code.

  • IOS7 DHCP IP address scopes being depleted

    I work for a large school district in Texas. We have a large deployment of iPads (10,000+) as well, we encourge BYOD.
    Our district has recently updated to iOS7. We now are experiencing IP address scopes running out of IP's, 6000 per campus for students, 5 campuses. With some testing we found the iOS7 devices leave the network - IE: go to sleep mode or disassociate from wireless in some fashion, generally for just a short period, 1 hr or 2. Once the iOS7 devices rejoin the network they are not keeping their original IP address and allocated another IP thus in a days time depleting IP addresses.
    Our DHCP lease times are set for 8 hours.
    We have tested this with iOS6 devices and these devices leave and rejoin and retain their original IP address from the scope.
    I was wondering if any other ISD or other enviroment with a large deployment of iOs devices have seen this problem?
    Thanks
    LB

    Hi All,
    Found this thread when searching for a solution to a similar dhcp problem on Friday.
    I came across this issue when building a wireless env similar to LB_MISD. Although in my env I have a linux server for dhcp and have two pools (one for known and another for unknown clients). Ios 7 devices were actually making so many requests it caused the DHCP server to stall at times.
    From the logs I noticed that I had problems with unknown clients but not with known clients ..... the difference - an assigned hostname in dhcp for the known clients.
    IOS 7 seems to require a hostname be given to the client device with the rest of the dhcp offer. To get around this I added an extra line to the dhcp pool that send the clients mac address back as it's hostname. It does not appear to actually get used by anything but does seem to fix the problem.
    "option host-name = concat ( binary-to-ascii (16, 8, ":", substring (hardware, 1, 6));"
    I don't know what the equivalent config would be for a windows server or home router - although a workaround might be to grab the mac addresses of all the IOS 7 devices and reserve an address and create a hostname for each device --- a pain yes but at least the dhcp server may work for everyone else?

Maybe you are looking for

  • Kin two m- PLEASE REPLY WITH HELP IMMEDIATLEY!

    I downloaded the Zune software on my computer for the KIN two phone. I downloaded and am using the free 14 day trial. I plugged my phone in with the USB cable, and dowloaded some music. Then i unplugged it, and all the pictures from my cell phone are

  • STO Interplant Excise

    Hi, I want to know when we do STO between plants for raw material. Which excise register gets hit in both the plants. What are the excise entries. Please tell me the usual practice

  • Changing timestamps on a bunch of photos

    I just got back from vacation. Half way through the vacation my camera died. I swapped the memory card into my daughters camera and kept shooting. However it looks like the timestamp settings on my daughters camera were set to 2007. So when I downloa

  • Unable to create package shares on distribution points

    For any OSD packages in our environment (like images, driver packages, etc) I always check the option "Copy the content in this package to a package share on distribution points", so that we are able to run content directly from the DP's in a task se

  • I want to use dial-up on the move

    I'm going away next week, and the hotel I'll be staying at doesn't have broadband or wireless internet. I know it has phone lines in the room that I'll be able to connect to, but does anyone know any dial-up providers I can use with my ibook, that me