How garbage collection works in spring framework?

Hi,
Whether we are using or not, all objects are created and stored in beanfactory in spring frramework.
So how garbage collection will work here?
Thanks in advance

It depends on the scope, by default beans are singletons and will not be garbage collected.
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes

Similar Messages

  • How to develop and deploy Spring framework app in Sun One App Server 8.1

    Hi,
    Can anyone give sample on how to develop and depoly spring framework application in J2EE 1.4 Server or Sun One App Server 8.1 .
    Its very urgently needed for my project to learn and implement spring framework i would very thankful if any one can help.
    Thanking You
    Naveen

    Pretty standard for AS8 to deploy Spring. The only thing to watch for is the security manager, which you'll probably want to turn off.

  • Can someone explain how garbage collector works in this program ?

    class Chair {
    static boolean gcrun = false;
    static boolean f = false;
    static int created = 0;
    static int finalized = 0;
    int i;
    Chair() {
    i = ++created;
    if(created == 47)
    System.out.println("Created 47");
    public void finalize() {
    if(!gcrun) {
    // The first time finalize() is called:
    gcrun = true;
    System.out.println(
    "Beginning to finalize after " +
    created + " Chairs have been created");
    if(i == 47) {
    System.out.println(
    "Finalizing Chair #47, " +
    "Setting flag to stop Chair creation");
    f = true;
    finalized++;
    if(finalized >= created)
    System.out.println(
    "All " + finalized + " finalized");
    public class Garbage {
    public static void main(String[] args) {
    // As long as the flag hasn't been set,
    // make Chairs and Strings:
    while(!Chair.f) {
    new Chair();
    new String("To take up space");
    System.out.println(
    "After all Chairs have been created:\n" +
    "total created = " + Chair.created +
    ", total finalized = " + Chair.finalized);
    // Optional arguments force garbage
    // collection & finalization:
    if(args.length > 0) {
    if(args[0].equals("gc") ||
    args[0].equals("all")) {
    System.out.println("gc():");
    System.gc();
    if(args[0].equals("finalize") ||
    args[0].equals("all")) {
    System.out.println("runFinalization():");
    System.runFinalization();
    System.out.println("bye!");
    } ///:~
    This code is From Bruce Eckel's "thinking in Java"
    Here is what I understand and what I don't
    At a certain point during the execution of the while loop (in the method main), the garbage collector kicks in and will call the method finalize() -
    I am at a loss as to what happens afterwards -
    Do the chairs continue to get created (which means the variable i keeps incrementing) and the finalize method keep getting called (which means finalized keeps incrementing) till the system realizes it is really low on memory and starts reclaiming memory ie i now starts decrementing ?
    What I would like to know is the exact flow or execution of the code after the garbage collector starts kicking in ie. what happens to the variables "i" (does it increment and then decrement), "created" (does it keep incrementing ), "finalized" (does it keep incrementing) and when is the if i==47{ } statement within finalize() get executed.
    There is no part of the code where i is being decremented (so I am guessing that it is the garbage collector reclaiming object memory that must be decrementing it).
    I am really confused -unfortunately there's very little in the book that really explains the flow of execution after the garbage collector kicks in and finalize() is called.
    Any help would be greatly appreciated

    Nice example, but Bruce chose some suboptimal names, I think.
    "i" can be thought of as the "ID" of a given Chair (note that it is not static). It is neither incremented nor decremented - it's just assigned from "created". This lets us identify specific chairs (like, say, "Chair #47").
    "created" is a running total of the number of times the Chair constructor has been called.
    "finalized" is a running total of the number of Chairs that have been finalized.
    The process starts creating Chairs as fast as it can. Eventually, memory gets low, and gc() starts collecting Chairs. While that's happening, chairs are still being created in the main Thread. So "created" and "finalized" may both be incrementing at the same time.
    When gc() picks Chair#47, the finalizer code sets a flag that causes new Chairs to stop being created. This causes the program to fall out of the while() loop, and the program spits out its data and exits.
    On my machine, the program created 29,542 chairs before exiting.
    Remember - often, gc() runs only when/if the JVM decides it's running low on memory. Specifics depend on the JVM and the startup options you use - some JVMs are very, very clever about doing incremental garbage-collection these days.
    Does that make more sense?
    Grant
    (PS - it's very, very good that you posted a working code sample. But learn about the \[code\] and \[code\] tags, please - makes your sample WAY easier to read...)

  • How strong ,soft ,weak ,phantom references are used in garbage collection

    Hi
    to all here.I have doubt that how garbage collection is deciding to cleaning up heap , and what are the roles of strong , soft , weak and phantom reference in garbage collection, i went throgh sun's java docs but i couldn't get any clear idea about those , please can anyone explain me with nice examples for which i will be really thankful.

    See:
    http://java.sun.com/developer/technicalArticles/ALT/RefObj/

  • Garbage collecting threads

    I am doing the following:
    public class MyClass {
         private Thread t = null;
         public class testThread extends Thread{
           public void run(){
                  String logName = this.getClass().getName();
                  Logger.Print( logName );  // Basically prints logName to file
                  for( int i = 1; i<4; i++){
                         try{
                           Thread.sleep(100)
                           [do stuff]
                           Thread.sleep(100);
                         catch(InterruptedException e) { }
           public callThread(){
               if ( t != null ){
                        if( !(t.isAlive()){
                               t = new TestThread();
                               t.start();
               else{
                               t = new TestThread();
                               t.start();
    } What, I want to happen is a thread to finish and after that a new one to start, and once the old thread does not have any variable assoiciated to it anymore, it should get garbage collected as far as my java understnading goes, this is exactly what should happen, in duo time whenever the garabage collecter decides so. This is a very long time running program.
    And the log shows the names of the threads like Thread-1 , Thread-2, Thread-3 , Thread-4, basically this name is increased by one everytime the function callThread is called and the old thread finished running, is there a limit to how many times I can call it like if it is called 10 billion times, will I have Thread-10000000000 in my log? and will the garbage collection work as I think? I am a c++ programmer so I do not trust it 100%, I really feel like adding delete t; so I can feel confident it is really gone before I do a t = new TestThread(); hehe C++ sickness??
    Please give me advice on this!!! and I will be very happy!
    Edited by: dakiar on Mar 19, 2008 8:18 AM

    dakiar wrote:
    What, I want to happen is a thread to finish and after that a new one to start,Use join(), rather than looping and checking isAlive, in order to determine when a thread has died.
    while (true) {
      Runnable r = new MyRunnable(); // You have no reason to extend Thread. It's preferable to implement runnable.
      Thread t = new Thread(r);
      t.start();
      t.join();
    and once the old thread does not have any variable assoiciated to it anymore, it should get garbage collected as far as my java understnading goes,It will become eligible for GC. There's no guarantee when or even if it will actually be GCed, other than that GC will at least happen before OutOfMemoryError.
    And the log shows the names of the threads like Thread-1 , Thread-2, Thread-3 , Thread-4, basically this name is increased by one everytime the function callThread is called and the old thread finished running, is there a limit to how many times I can call it No.
    like if it is called 10 billion times, will I have Thread-10000000000 in my log? Perahps. Or if Thread uses an int then it might wrap around to Integer.MIN_VALUE and give Thread--2147483648.
    You know you can assign your own names to the Threads.
    and will the garbage collection work as I think? It will work fine, and that has nothing to do with thread names.
    I am a c++ programmer so I do not trust it 100%,So, you think that you managing memory ad-hoc in every program you write when you're trying to focus on implementing the business requirements of your app will be better at it than the guys who were specifically focussed on writing memory management that would be handled consisently by the computer, and has been continuously refined, not to mention tested by thousands of Java developers over the last dozen or so years?
    I really feel like adding delete t; You can't and you don't need to.

  • How to integrate BIP API in Spring framework

    Hi everyone,
    Is it possible to integrate Oracle Business Integration Publisher API with "Spring framework" ? I want to get the reports generated using Oracle BI Publisher API but our project is spring framework based. Anyone any ideas? How to do so ?
    Thanks !

    Pardon my ignorance, if I checked something wrong in the BIP documentation but that web services part require some SQL queries to be written right? We are not supposed to make our application so complicated. I guess, if I only add jars, then BIP code would work just like simple POJOs. Not sure
    Will let you know once I will solve this problem.
    Thanks !

  • * How about flash play 8 Garbage Collector working?

    Hi, I need to add some Image controls dynamically, yes,the
    number of those are unpredictable.
    My code to create them like this:
    quote:
    public function addImg(name:String, x:Number, y:Number):void
    var sm1:Image = new Image();
    sm1.source = "imgs/down_medium.gif";
    sm1.name = name;
    sm1.x = x;
    sm1.y = y;
    this.addChild(sm1);
    Then, it appeared in my application. if I add numbers of
    Image in my stage, they eat my memory crazily.
    so I want to kill some Image which is not in use, but I
    crashed.
    An Image named "img4kill" in stage, it's index in
    this.getChildren() is4, and it holds a image which size is about
    230K.
    I tried to kill it like this:
    quote:
    this.removeChildAt(4);
    yes, it's remove from the stage in faith, but I watched the
    memory that the browser using, before and after killing it.
    I found the memory it takes is not released.
    How can I kill it from both the stage and memory ? I tried
    the global function "delete" ,but failed too.
    I know that flash play 8.5 and later use a powerfull
    GC(garbage collector), but in the sample above, it dose't work for
    me.
    who can save me from this mud layer?any ideas?
    thanks a lot .
    (sorry about my ugly english)
    [email protected]

    Don't worry, the garbage collector will work very well in this case (and in every other case too :) ). It will only collect an object when no more references are pointing to it. Your array still holds a reference to all the items it contains (unless you explicitly do array[index] = null).
    There are only three ways that I know of to destroy a reference to an Object: 1). Set the reference to null 2). Let the reference fall out of scope 3) reassign the reference to another object
    The garbage collector will also be able to collect objects that have a cyclical references as long as none of the objects in the cycle are reachable.
    It pays to understand the ins and outs of garbage collection and memory management in the VM. Knowing that will let you know, for example, that allocating an Object in Java is a very cheap operation (while it is pretty expensive in C/C++).
    Check http://www.ibm.com/developerworks/java/library/j-jtp10283/ and http://www.ibm.com/developerworks/java/library/j-jtp11253/ and for more details about the GC
    Also don't worry about the performance impact of setters and getters, either the javac compiler or the Virtual Machines Just In Time Compiler will inline those small methods.
    In short don't worry about such low level performance problems and concentrate on your coding style and algorithms. The Hotspot JVM is an amazingly efficient piece of software. It also include a lot of optimizations that work very well in optimizing "standard" code. The more normally you code, the faster your program will be, so don't try clever optimizations tricks, they probably won't work well in java.
    Read the following articles for some discussion about performance in Java:
    http://www.ibm.com/developerworks/java/library/j-jtp04223.html
    http://www.ibm.com/developerworks/java/library/j-jtp09275.html
    http://www.ibm.com/developerworks/java/library/j-jtp01274.html

  • How to encourage jvm to garbage collect?

    Hello,
    I am working with an application that would benefit from more frequent garbage collection. It is running on a hefty machine, with multiple processors and more than 4 gigs of memory available for the JVM. Right now, we are setting the max heap size to 3 gigs.
    The problem is that objects are accumulating, but are not being collected. During a particular operation that I am profiling, over 1 gig of objects are created, but are never collected. If I do a manual garbage collect (using jprofiler), they are all collected. There is no good way to load these objects in another way, or to create fewer objects.
    I have spent a few days playing with -XX:MaxNewSize, -XX:NewSize, -XX:MaxHeapFreeRatio, -XX:TargetSurvivorRatio, and even -XX:+UseParNewGC. Unfortunately, I am unable to encourage the JVM to collect these objects automatically.
    Are there any tricks that I am missing? Does anyone know any good way to encourage the JVM to collect garbage after a certain threshhold in the new generation?
    Thanks,
    --Jeff                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You can try this!
    How do I set the JVM's heap size?
    On machines with limited memory (less than 384MB), it is recommended that you set the initial heap size lower than the default. Open the configuration file etc/netbeans.confin a text editor and modify the options in netbeans_default_optionssetting. Decrease the option -J-Xmx128mto -J-Xmx96m and the option -J-XX:MaxPermSize=96mto -J-XX:MaxPermSize=64m. Save the file and restart the IDE.
    Bear in mind that UI responsiveness may be affected when the heap utilization gets close to its limit. Should you encounter an OutOfMemoryError, you need to increase Xmx or XX:MaxPermSize back to the default, or even higher.
    Similarly when running on a machine with more memory it might be useful to increase the maximum size of the heap, especially when working with larger projects. Use the page linked below to get more details on this topic.
    Applies to: NetBeans 4.x, 5.0
    Platforms: All

  • How to Change the Garbage Collection Algorithm in WLS 9..2

    Hi All
    I am trying to find out the way to configure the GC algorithm in weblogic 9.2 to type bea.Jmapi.GarbageCollector@.
    By default it is showing ‘Nursery, parallel mark, parallel sweep’ . We were trying to change it to generational (two-spaced) with a parallel mark algorithm and a concurrent sweep algorithm or bea.Jmapi.GarbageCollector .
    To change the same I modified the memory argument in commenv.cmd to set MEM_ARGS=-Xms128m -Xmx256m -XXsetGC:genparcon
    Still Garbage Collection Statistics section in web logic console shows the same default value.
    Could anyone tell me if I am missing something?
    thanks in advance

    There is nothing is WebLogic that will define the JVM GC algorithm, that is up to the JVM settings that are normally configured using params in the start scripts.
    If you are using JRockit, you can ask in the forums but the JVM documentation should really be sufficient.
    JRockit
    Same thing for the Sun JVM, there is lots of information out there on how to change the GC algorithm.
    The thing that is nice about JRockit is that you can use the Mission Control tooling to take recordings, look at the GC's and make adjustments easily. Sun has some tooling as well with jvmstat (and visualgc), but I'm not as familiar with it.
    http://java.sun.com/performance/jvmstat/
    Both of those tools would be much preferred to printing the GC info to a file and trying to parse it in my opinion.

  • DocumentBuilderFactory.newInstance() only works after garbage collection

    Hi all,
    I am stucked with a strange behaviour of "DocumentBuilderFactory.newInstance()".
    I use the DocumentBuilderFactory in an applet
    to parse an xml-file.
    My applet starts ok until the line 5 (newInstance) gets called.
    At this time it seems that nothing happens anymore and that
    the applet fails to continue.
    But when I open up the java console and hit
    g (garbage collection) the xml parsing continues immediatly
    and my applet completes loading and runs ok.
    1 private void genarteDomNodes() {
    2 try {
    3 // ---- Parse XML file ----
    4 DocumentBuilderFactory factory =
    5 DocumentBuilderFactory.newInstance();
    6 DocumentBuilder builder =
    7 factory.newDocumentBuilder();
    8 Document document = builder.parse(
    9 new URL(this.myModules_xml).openStream() );
    10 // ---- Get list of nodes to given element tag name ----
    11 NodeList ndList =
    12 document.getElementsByTagName("meter-group");
    13 printNodesFromList( ndList );
    14 } catch( SAXParseException spe ) {
    15 ...
    16 } catch( SAXException sxe ) {
    17 ...
    18 } catch( ParserConfigurationException pce ) {
    19 ...
    20 } catch( IOException ioe ) {
    21 ...
    22 }
    23 }

    I am still stucked with this problem. But I found out how to enable JAXP debug output for applets (setting system properties isn't allowed for applets).
    This puts somemore output to the java console. It might help someone to understand my problem. I also printed some debug messages to track down my problem.
    Following is the console output of my applet:
    URL of XML to parse = "http://10.110.132.195/c8000-modules.xml"
    entering "genarteDomNodes"
    just before calling "DocumentBuilderFactory.newInstance()"
    JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
    !!! at this time the applet "hangs" and nothing happens;
    until I hit the "g" button. Then applet continues immediatly and prints:
    JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
    JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl using ClassLoader: sun.plugin.security.PluginClassLoader@32060c
    After invoking the garbage collector the applet continue to parse the xml file and runs as expected.
    Can someone help me please.

  • How to make external SWFs garbage collected in Air for iOS?

    My app uses lots of external SWFs( well they are actually included in the app with a folder but they aren't embeded ) and they do not contain any bitmapdata, only vector graphics. The problem I'm having is that they seem to be never garbage collected and System.privateMemory keeps increasing as the app loads more SWFs.
    Since those SWFs only contain vector graphics, I simply nullify all the variables that are holding reference to SWF file and call System.gc().. But it doesn't seem to be working. What would I need to do for the garbage collector to clean the SWFs?
    I'm using Air for iOS 3.5.0.1060 and ActionScript3.0.

    Yes I'm calling System.gc() twice. I tried using loader.unloadAndStop(true) and it seems SWFs are being garbage collected but another problem has surfaced. When repeatedly loading and unloading SWF in a short period, the air garbage collector sometimes fails to work.
    I've tested loading and unloading same SWF 50k times and checked trace.  Occasionally, garbage collector misses to collect garbage like below( swf #45119 is not being garbage collected).
    [UnloadSWF] main.swf/[[DYNAMIC]]/45115
    [UnloadSWF] main.swf/[[DYNAMIC]]/45116
    [UnloadSWF] main.swf/[[DYNAMIC]]/45117
    [UnloadSWF] main.swf/[[DYNAMIC]]/45118
    [UnloadSWF] main.swf/[[DYNAMIC]]/45120
    [UnloadSWF] main.swf/[[DYNAMIC]]/45121

  • How Ajax works with Struts framework

    How Ajax works with Struts framework .
    Thanks
    Ramki

    So we must write file name(like abc.do), If am using struts <html:link > tag like <html:like action="abc" >Click</html:link>, so with ajax we must call like <a href ="abc.do">Click</a> .
    But there is a problem, if am using ,
    <servlet-mapping>
    <servlet-name>MainServlet</servlet-name>
    <url-pattern>/r/*</url-pattern>
    </servlet-mapping>
    or
    <servlet-mapping>
    <servlet-name>MainServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    here i am changing web.xml file based on client interest. At those situation we must change all jsp pages for <a href ="/r/abc">Click</a> .like,.
    It's very difficult.
    Is any other way to use ajax with Struts (Only struts tags)
    Thanks
    Ramki

  • How do collection updates really work?

    Hi,
    Few questions about collection updates.
    I have been trying to figure out the most effective way to implement collection updates so, that there would be minimal delay in adding a workstation to collections. The documentation on how the updates exactly work is however a bit vague and the functionality
    seems to have no clear course of action... This is going to be a long post, since there's much to describe.
    We have two main collection structures. One is for software and the other one is for Active Directory. 
    Software structure has collections for each software and each software collection is consisted of direct members, Query rules for AD Security Group members and included collections from Active Directory collection structure.
    Active Directory collection structure is a tree-like structure where the root collection and all descending collections include their child items. The real query for workstations from AD is in the last collection/node of the tree. For example in the picture
    "Staff" collection has collection rules to include "Faculty1" and "Faculty2". Faculty1 has rules which include "dept1" and "dept2" to the collection and so forth. All collections are limited to All Workstations
    (members queried from AD), which is limited to All Systems. 
    I have disabled all incremental and scheduled updates from each collection (excl. built-in collections) and set hourly updates on All workstations. All built-in collections are incrementally updating. Now, this should only update all workstations collection
    and the rest should be left alone? Nope. When the All Workstations collection schedule triggers almost 2/3 of all other collections are refreshed too. There however seem to be no consistency what collections are updated. First I thought that all collections
    which have All workstations as limiting collection would update, but it does not seem to work like that. 
    First question: Does anyone have any idea how the update works in this case? Does updating limiting collection affect other collections?
    I have created an SQL query to easily see the last refresh time of a collection. The query also shows all manually made "Update collection membership" requests with time and what the settings are in that collection. This query is scoped on the view
    "vCollections". 
    Second question: This list shows one extra collection which cannot be seen from ConfigMgr console. The collection has ID "SMSOTHER" and is named "All custom resources". What is this for? The collection updates on schedule and has incremental
    updates turned on.
    Our organization has around 900 collections in total and if all collections are updated (full update) synchronously it will take almost 30 minutes to complete (BTW, why is the performance so poor and why no async updates?). Software collections probably are
    easiest to do with incrementals, but using schedule on all AD collections with the current functionality seems like an overkill. I have tried scheduled updates on different levels of the structure, but none of these seem to have the constant effect of updating
    all child collections also.
    How does updating one collection affect other collections? Do the included collections get updated as well?
    Would be great if there was a comprehensive documentation about collection updates.
    BR,
    Juha-Matti

    Hi,
    First question:
    Based on my knowledge, when All Workstations collection schedule triggers, all other collections related to this collection would be updated too.
    Second question:
    The collection “All custom resources” hasn’t been documented. I think it might be reserved for future
    use.
    Best Regards,
    Joyce Li
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Object [5610] : garbage collection is off. Anyone tell me how to turn it on ?

    Can anyone tell me how to turn garbage collection on ? I'm getting objct: [5610] garbage collection is off.

    Press Cmd-F5 together (that's Cmd + the F5 key, two keys only,  not F-5.)

  • How can I prevent class garbage collection????

    Hi,
    Is there a way to prevent a class from being garbage collected without using the -noclassgc option? Is there some code I can include in a class that tells the JVM not to garbage collect that particular class?
    Thanks in advance,
    Jacob.

    The code shown below (slightly modified from yours) should work correctly on any 1.0.x throught 1.4 JVM.
    Look at this article for further info: http://www.javaworld.com/javaworld/javatips/jw-javatip52.html
    public class SQLManager extends PoolManager {
        private static SQLManager myself;
        //code.........................
        public static SQLManager getInstance() {
            // This version of a getInstance method suffers from the use of the
            // broken (unreliable) double checked locking idiom.  It should never
            // be used on a system with more than one processor and is ill-advised
            // any other time.  It can  lead to accesses to uninitialized objects.
            // See http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html
            // or http://c2.com/cgi/wiki?DoubleCheckedLockingIsBroken
            // So despite its common appearance in books and pattern repositories,
            // it should not be used.
            if (myself == null) {
                synchronized(SQLManager.class) {
                    if (myself == null)
                        myself = new SQLManager();
            return myself;
        private SQLManager() {
            livethread();
            //code.........................
        void livethread()
            System.out.println("##############################################################");
            System.out.println("###################Live Thread called#########################");
            System.out.println("##############################################################");
            Thread thread = new Thread()
                public void run()
                    // added this code to ensure that run() actually is getting
                    // called
                    System.out.println("##############################################################");
                    System.out.println("#################### Thread Started ##########################");
                    System.out.println("##############################################################");
                    Class myClass = SQLManager.class;
                    while (true)
                        try
                            synchronized (myClass)
                                myClass.wait();
                        catch (InterruptedException ex)
                            System.out.println("##############################################################");
                            System.out.println("###################Thread interrupted#########################");
                            System.out.println("##############################################################");
                        finally
                            System.out.println("##############################################################");
                            System.out.println("################### Something Happened #########################");
                            System.out.println("##############################################################");
                    System.out.println("##############################################################");
                    System.out.println("#################### Thread Dead?? ##########################");
                    System.out.println("##############################################################");
            thread.setDaemon(true);
            System.out.println("##############################################################");
            System.out.println("#################### Starting Thread #########################");
            System.out.println("##############################################################");
            thread.start();
        //code.........................
    }

Maybe you are looking for