Is Finalizer guadian idiom safe??

Is finalizer guardian idiom safe? which is written on 'Effective java programming language.'
In VM specification, there is no specific guide how GC work or what kind of algorithm it use.
So it is uncertain which one of finalize() method invoked first.
To finalizer guardian work correctly, subclass's finalize() method must be invoked first and then finalizer guidian's finalize() method must be invoked.
But as I said, guidian's finalize() method could invoked first.
Effective java programming language is best seller. But I have not heard that finalizer is dangerous. What I think is wrong?? If what I think is wrong please tell me why it is correct. If you think I am right, please tell me also..

This thread has a good discussion. Finalize does have some problems associated with its use.
http://forum.java.sun.com/thread.jsp?forum=31&thread=273275

Similar Messages

  • Regarding Garbage collection

    It says the finalize() method must be used only when its failure to execute predictably will not cause problems for the application. How does one ensure that problems would not be caused in the application if the finalize method fails?

    mehulnewton wrote:
    It says the finalize() method must be used only when its failure to execute predictably will not cause problems for the application. How does one ensure that problems would not be caused in the application if the finalize method fails?OP:
    It's not a matter of making sure that the finalize() contents are safe. According to the official Java documentation, if an exception is thrown in finalize() it will be silently ignored.
    All it's saying is that you shouldn't put anything in there that controls your program flow. For example, this would be a bad idea:
    public class Main {
       public static boolean run = true;
       public static void main() {
          WeirdObject object = new WeirdObject();
          while ( run ) { /*do nothing*/}
       private static class WeirdObject {
          protected void finalize() throws Throwable {
             super.finalize();
             run = false;
    }

  • What's the safe way to do initialization and finalization?

    Hi all,
      I have a thrid party driver for an external device to use in my CVI. I have to initialize the driver when the main panel is initialized and HAVE to release the driver upon the closing of the application. In my code, the main structure is something like
    int main (int argc, char *argv[])
        char s[10];
        if (InitCVIRTE (0, argv, 0) == 0)
            return -1;    /* out of memory */
    <code removed by Moderator>
    Here I put the code to initialize the driver before DisplayPanel and will release the driver at the end of the main function. I am wondering if this is safe and the right way to do that? The reason why I am asking is the external driver is so strange, if the application using that not release the driver properly, other application can't use it unless to reboot the system.
    I search online and see someone to release the driver in the event EVENT_CLOSE of the main panel, is that better way to do the finalization here? If so, any function like EVENT_START or EVENT_INITIALIZATION so I can do some initialization there?
    Thanks.
    Solved!
    Go to Solution.

    Hi Dragondriver,
    It sounds like the person used event_close in order to close out the reference to the driver if the UI is exited. This makes sense. You could include both without a problem. For example, you could initialize and close out the reference to the driver in each subprogram or subroutine you write that uses the driver, in addition to automatically closing out any references to it if the UI is closed accidentally in the middle of a subroutine. This would be a good way to do it.
    Regards,
    Basil
    Applications Engineering
    National Instruments

  • Finalize() method being called multiple times for same object?

    I got a dilly of a pickle here.
    Looks like according to the Tomcat output log file that the finalize method of class User is being called MANY more times than is being constructed.
    Here is the User class:
    package com.db.multi;
    import java.io.*;
    import com.db.ui.*;
    import java.util.*;
    * @author DBriscoe
    public class User implements Serializable {
        private String userName = null;
        private int score = 0;
        private SocketImage img = null;
        private boolean gflag = false;
        private Calendar timeStamp = Calendar.getInstance();
        private static int counter = 0;
        /** Creates a new instance of User */
        public User() { counter++;     
        public User(String userName) {
            this.userName = userName;
            counter++;
        public void setGflag(boolean gflag) {
            this.gflag = gflag;
        public boolean getGflag() {
            return gflag;
        public void setScore(int score) {
            this.score = score;
        public int getScore() {
            return score;
        public void setUserName(String userName) {
            this.userName = userName;
        public String getUserName() {
            return userName;
        public void setImage(SocketImage img) {
            this.img = img;
        public SocketImage getImage() {
            return img;
        public void setTimeStamp(Calendar c) {
            this.timeStamp = c;
        public Calendar getTimeStamp() {
            return this.timeStamp;
        public boolean equals(Object obj) {
            try {
                if (obj instanceof User) {
                    User comp = (User)obj;
                    return comp.getUserName().equals(userName);
                } else {
                    return false;
            } catch (NullPointerException npe) {
                return false;
        public void finalize() {
            if (userName != null && !userName.startsWith("OUTOFDATE"))
                System.out.println("User " + userName + " destroyed. " + counter);
        }As you can see...
    Every time a User object is created, a static counter variable is incremented and then when an object is destroyed it appends the current value of that static member to the Tomcat log file (via System.out.println being executed on server side).
    Below is the log file from an example run in my webapp.
    Dustin
    User Queue Empty, Adding User: com.db.multi.User@1a5af9f
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    Joe
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin pulled from Queue, Game created: Joe
    User Already Placed: Dustin with Joe
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    INSIDE METHOD: false
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    User Dustin destroyed. 9
    User Joe destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    It really does seem to me like finalize is being called multiple times for the same object.
    That number should incremement for every instantiated User, and finalize can only be called once for each User object.
    I thought this was impossible?
    Any help is appreciated!

    Thanks...
    I am already thinking of ideas to limit the number of threads.
    Unfortunately there are two threads of execution in the servlet handler, one handles requests and the other parses the collection of User objects to check for out of date timestamps, and then eliminates them if they are out of date.
    The collection parsing thread is currently a javax.swing.Timer thread (Bad design I know...) so I believe that I can routinely check for timestamps in another way and fix that problem.
    Just found out too that Tomcat was throwing me a ConcurrentModificationException as well, which may help explain the slew of mysterious behavior from my servlet!
    The Timer thread has to go. I got to think of a better way to routinely weed out User objects from the collection.
    Or perhaps, maybe I can attempt to make it thread safe???
    Eg. make my User collection volatile?
    Any opinions on the best approach are well appreciated.

  • Windows 8 HP Pavilion dv7-4285dx Upgrade results in black screen after intallation finalizes.

    I have a 2011 HP Pavilion dv7-4285dx with Windows 7 64 bit Home premium installed.  The notebook/laptop has a AMD Radeon HD 6300M series display adapter with driver version 9.2.2.0 dated 9/27/2012 and an ATI technologies Intel HD Graphics display adapter with driver version 8.7771.1.0.  The notebook/laptop has not had a hardware upgrade and contiains the orignal factory OS. BIOS is current to latest available.
    The issue I had while upgrading to Windows 8 is after the install finalizes (settings and preferences are entered) and the system boots to the tiles screen, the display works fine.  Clicking to the desktop works only for a few moments before the screen goes dark. Pressing the power button and/or closing/opening the lid results in at times a black screen (no power to the screen) or black screen (power to the screen) or a black screen where only the mouse pointer is visible and moves around the screen.  Restarting the computer results in a repeat of the issue at times while other times it will boot directly to what appears to be the windows desktop. You can interact with the file folder icon on the task bar as well as internet explorer, and you can get the charms bar and tile screen. Any attempt to open computer management or any control panel or task manager will open the window as an icon on the task bar.  You can mouseover the icon to "preview" a small version of the window but you can not click on it to maximize.
    I attempted the following workarounds:
    1) Clean install of Windows 8: Installs but fails with same result as above
    Refresh PC from windows 8 rescue media: Works slightly longer until AMD driver fails and then reverts to situation above. 
    2) Uninstalling all display adapters (via computer management) and then upgrading to Windows 8: Results in microsoft drivers getting installed, works much as refresh above until AMD driver fails and then reverts to above situation.
    3) In Scenarios 1 and 2,  I also tried to use windows update within Win8 to update the drivers there are updated MS drivers available ,(dated as late as 10/27/2012) but intalling those drivers also resulted in a failure of the adapter within a short period of time as did NOT updating the drivers.
    4) Disabling display adapters and then restarting:  Results in a BSOD (Blue Screen) IRQL_NOT_LESS_OR_EQUAL Stop: 0x0000000A error during boot as the OS runs into trouble with the driver before Windows 7 boots.  This happens if one or both drivers are disabled.
    5) Disabling display adapters before in-place upgrade to Windows 8 results in the Windows 8 equivalent of a BSOD and results in the system shutting down and then reverting to Windows 7.
    Through research, I determined some ppl had luck connecting another monitor/HD TV through VGA/HDMI and then using the function-screen button to switch, with my system this resulted in the same issue displayed on the TV/Monitor. There are also updates to ATI and Catalyst center available including drivers and installing these do not remedy the issue. Intel was checked and there are no drivers available as HP uses a "custom" driver for intel.  Attempting to install any of these Intel drivers will result in a fail with a compatiblity error.
    Windows 8 has no safe mode ability from the windows 8 rescue media disk, you cannot F-8 as you could in the preview. Safe mode must be reached via charms, settings, startup and then selecting safe mode as a boot option, which is not available as the display adapter malfunctions.  In those scenarios where I was able to get a windows desktop to boot up as in the first paragaph I can get to the restart settings via charms, but clicking to bring up the restart menu requires another window to open which is only visible as a "preview" on the windows task bar.
    if you are going to attempt to try any of these,
    1) Use a third party software to image your pre-win 8 upgrade system that you can boot into from USB or CD;
    2) Before starting the process, disable the UAC prompt and remove any passwords from logon, as those things will require you to interact with the OS and you will not be able to do this when the adapters fail.  The screen will shadow out as it usually does but the prompt will not be viewable.
    3) Create an ISO image of the Win8 install media and write down the product key. If you are able to get a successful boot, before the drivers fail, create a Windows 8 rescue media disk.
    I spoke with HP tech support this morning (10/29/2012) they are aware of the issues and they lie with the display adapters.  They are working toward a solutuion but there are none available at this time and no date when they will be available.  They recommend checking the support website and having the web page autoscan your PC as the drivers will show there when they are posted and they will be installable from Windows 7 so there will be no issue with upgrading to Windows 8.  Bottom line, do not upgrade to Windows 8 at this time.
    MS Tech support escalation tier reps also informed me there is no present workaround available.
    Hope this helps and saves somebody some time!
    JJ

     My laptop sat at BestBuy from Friday night until today (10-31-12)! They couldn't figure out how to fix the problem so I finally told them to revert my latop back to Windows 7! I hope HP reads these and will hurry up and make the updates needed so that I can run Windows 8 on my Laptop! I just bought mine in July of last year there is nothing wrong with it and after dropping about $1200.00 for my dv7-4285dx along with the Best Buy Geek Squad package I do not feel like having to drop more money into another laptop!! PLEASE HURRY AND FIX THIS I DIDN"T DROP $69.99 plus tx to not be able to use Windows 8! Even before I did the upgrade I had the GEEk Squad check to make sure I could make the upgrade and was told this laptop well surpasses the required minium to run Windows 8!!!!!!

  • Java.util.Locale not thread-safe !

    In multithreading programming, we know that double-checking idiom is broken. But lots of code, even in sun java core libraries, are written using this idiom, like the class "java.util.Locale".
    I have submitted this bug report just now,
    but I wanted to have your opinion about this.
    Don't you think a complete review of the source code of the core libraries is necessary ?
    java.util.Locale seems not to be thread safe, as I look at the source code.
    The static method getDefault() is not synchronized.
    The code is as follows:
    public static Locale getDefault() {
    // do not synchronize this method - see 4071298
    // it's OK if more than one default locale happens to be created
    if (defaultLocale == null) {
    // ... do something ...
    defaultLocale = new Locale(language, country, variant);
    return defaultLocale;
    This method seems to have been synchronized in the past, but the bug report 4071298 removed the "synchronized" modifier.
    The problem is that for multiprocessor machines, each processor having its own cache, the data in these caches are never synchronized with the main memory.
    The lack of a memory barrier, that is provided normally by the "synchronized" modifier, can make a thread read an incompletely initialized Locale instance referenced by the static private variable "defaultlocale".
    This problem is well explained in http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html and other documents about multithreading.
    I think this method must just be synchronized again.

    Shankar, I understand that this is something books and articles about multithreading don't talk much about, because for marketing reasons, multithreading is supposed to be very simple.
    It absolutely not the case.
    Multithreading IS a most difficult topic.
    First, you must be aware that each processor has its own high-speed cache memory, much faster than the main memory.
    This cache is made of a mixture of registers and L1/L2/L3 caches.
    Suppose we have a program with a shared variable "public static int a = 0;".
    On a multiprocessor system, suppose that a thread TA running on processor P1 assign a value to this variable "a=33;".
    The write is done to the cache of P1, but not in the main memory.
    Now, a second thread TB running on processor P2 reads this variable with "System.out.prinln(a);".
    The value of "a" is retrieved from main memory, and is 0 !
    The value 33 is in the cache of P1, not in main memory where its value is still 0, because the cache of P1 has not been flushed.
    When you are using BufferedOutputStream, you use the "flush()" method to flush the buffer, and the "synch()" method to commit data to disk.
    With memory, it is the same thing.
    The java "synchronized" keyword is not only a streetlight to regulate traffic, it is also a "memory barrier".
    The opening brace "{" of a synchronized block writes the data of the processor cache into the main memory.
    Then, the cache is emptied, so that stale values of other data don't remain here.
    Inside the "synchronized" block, the thread must thus retrieve fresh values from main memory.
    At the closing brace "}", data in the processor cache is written to main memory.
    The word "synchronized" has the same meaning as the "sync()" method of FileDescriptor class, which writes data physically to disk.
    You see, it is really a cache communication problem, and the synchronized blocks allows us to devise a kind of data transfer protocol between main memory and the multiple processor local caches.
    The hardware does not do this memory reconciliation for you. You must do it yourself using "synchronized" block.
    Besides, inside a synchronized block, the processor ( or compiler ) feels free to write data in any order it feels most appropriate.
    It can thus reorder assignments and instruction.
    It is like the elevator algorithm used when you store data into a hard disk.
    Writes are reordered so that they can be retrieved more efficiently by one sweep or the magnetic head.
    This reordering, as well as the arbitrary moment the processor decides to reconciliate parts of its cache to main memory ( if you don't use synchronized ) are the source of the problem.
    A thread TB on processor P2 can retrieve a non-null pointer, and retrieve this object from main memory, where it is not yet initialized.
    It has been initialized in the cache of P1 by TA, though, but TB doen't see it.
    To summarize, use "synchronized" every time you access to shared variables.
    There is no other way to be safe.
    You get the problem, now ?
    ( Note that this problem has strictly nothing to do with the atomicity issue, but most people tend to mix the two topics...
    Besides, as each access to a shared variable must be done inside a synchronized block, the issue of atomicity is not important at all.
    Why would you care about atomicity if you can get a stale value ?
    The only case where atomicity is important is when multiple threads access a single shared variable not in synchronized block. In this case, the variable must be declared volatile, which in theory synchronizes main and cache memory, and make even long and double atomic, but as it is broken in lots of implementation, ... )

  • Inicio con MAVERICKS 10.9.2 y se cambia el idioma del teclado a ingles estadounidense.

    Cuando inicio Macbooks con OS X MAVERICKS 10.9.2, que acabo de reinstalar, se cambia el idioma del teclado a ingles estadounidense. Lo cambio en preferencias de sistema, pero al volver a iniciar... otra vez igual. 
    Es decir, no puedo cambiar el idioma del teclado por defecto a Español ISO, ni ningún otro. Siempre se establece por defecto el Ingles estadounidense. He cambiado la fuente de entrada, pero nada... se vuelve a poner el ingles por defecto.
    He probado tambien a cambiar el idioma desde el Terminal, eligiendo el número de idioma, pero... al volver a iniciar... otra vez igual.
    ¿Alguien podria echar una manilla?. Gracias.

    Try booting into safe mode (hold SHIFT key down while booting).

  • Clarification of the handle/body idiom in multi threaded applications

    Hello
    As some DBXML classes use the handle-body idiom (handle/body idiom in some docs), could someone please clarify the consequences of that in a multi threaded application like a web container?
    For 100% Java people, like me, this is known in the Java world as 'programming towards interfaces', or as the Bridge pattern; which is seen as good practice.
    Let's take an example. The class XmlQueryContext is not thread safe, but it has a copy constructor. Imagine that your web application has one XmlQueryContext, that we never use in a query, but that we prepare only to be copied in new threads. Is it thus safe to instantiate various new XmlQueryContexts using that copy constructor in various new threads and use them simultaneously?
    Thank you
    Koen
    PS What I am really asking here is if somebody could please translate the following to Java parlé:
    A copy constructor is provided for this class. The class is implemented using a handle-body idiom. When a handle is copied both handles maintain a reference to the same body.

    As a Java user you do not have to worry about how the C++ copy constructors behave. In the Java API if a copy constructor exists for the object, then the copy constructor will copy all of the original object's data into a new object (XmlContainer is the one exception to this rule, generally one should not use that copy constructor at all). So in short, what you plan to do will work.
    Lauren Foutz

  • 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

  • I uninstalled Thunderbird but when i try to reinstall it I keep getting a message that the system must be rebooted to finalize the uninstall, over & over again.

    I am using a laptop with Windows 7. For several weeks Thunderbird has been running very slowly & there are messages saying a script is running too long. So I decided to try to clean up all the mail boxes, but still get the messages...so then I decided to uninstall Thunderbird and this worked correctly & I rebooted the system (as it asked me to). But when I try to re- install Thunderbird I keep getting a message that the system must be rebooted to finalize the uninstall. I did this but the same thing happens each time I try to install...so now I have no mail application on my laptop. Most frustrating but fortunately I have an iPad...
    Can someone please advise? Thanks in advance

    you original problem is almost certainly your anti virus, I would also hazard a guess your new one is as well.
    Thunderbird does not require a reboot on install, or uninstall.
    try restarting the operating system in '''[http://en.wikipedia.org/wiki/Safe_mode safe mode with Networking]'''. This loads only the very basics needed to start your computer while enabling an Internet connection. Click on your operating system for instructions on how to start in safe mode: [http://windows.microsoft.com/en-us/windows-8/windows-startup-settings-including-safe-mode Windows 8], [http://windows.microsoft.com/en-us/windows/start-computer-safe-mode#start-computer-safe-mode=windows-7 Windows 7], [http://windows.microsoft.com/en-us/windows/start-computer-safe-mode#start-computer-safe-mode=windows-vista Windows Vista], [http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/boot_failsafe.mspx?mfr=true" Windows XP], [http://support.apple.com/kb/ht1564 OSX]
    ; If safe mode for the operating system fixes the issue, there's other software in your computer that's causing problems. Possibilities include but not limited to: AV scanning, virus/malware, background downloads such as program updates.

  • Initialization on demand holder idiom

    From Wikipedia I learnt that this code is thread safe:
    public class Something {
         private Something() {
         private static class LazyHolder {
              private static final Something INSTANCE = new Something();
         public static Something getInstance() {
              return LazyHolder.INSTANCE;
    }But can the same trick be used with a non-static method?
    public class Something {
        private static class LazyHolder {
            private static final Something INSTANCE = new Something();
        public Something getInstance() {
            return LazyHolder.INSTANCE;
    }How about using static blocks?
    public class Something {
        private static class LazyHolder {
            private static final Something INSTANCE;
            static {
                INSTANCE = new Something();
        public Something getInstance() {
            return LazyHolder.INSTANCE;
    }I'm asking this because I really want to initialize a time consuming object only once, but I can't expose static methods.
    Another thing, how about a thread safe lazy accessor (at instance level)? Can it be done without applying "synchronized" to the whole method?
        public synchronized Something getInstance() {
            if (something != null) {
                something = new Something();
            return something;
        }

    Peter,
    Thank you.
    Life cycle goes like this:
    ->Client receives a FacadeService (via a remote invocation, so I really don't have much control on how many instances are available, but I know there can be more than one FacadeService instance in memory).
    -> Client calls a method in his Facade Service instance
    -> The method perform heavy calculations, network access and database operations. When it is done, the result object gets cached locally and then returned to the client
    -> Client calls other method
    -> The same thing happen and other objects are cached locally.
    -> Client calls one of the above Methods
    -> method quickly return the cached result
    Client will use the Facade in a Concurrent environment, and it is our responsibility to make it all thread safe.
    So, what I want to do is mimic the behavior of Something like this:
    public class ServiceFacadeImpl {
        // Results are Immutable objects
        private Result1 result1;
        private Result2 result2;
        public Result1 getResult1() {
            if (result1 == null) {
                // heavy operation to create result1
            return result1;
        public Result2 getResult2() {
            if (result2 == null) {
                // heavy operation to create result2
            return result2;
    }In a thread safe fashion.
    Using "synchronized" methods would be a way... But I'm sure it can be done in a less restrictive way (having every method, even the ones that would simple return a cache result, waiting for other method to finish it's long operations in order to get the object lock just don't do it).
    public synchronized Result1 getResult1() {
            if (result1 == null) {
                // heavy operation to create result1
            return result1;
        }Double-checked locking isn't thread safe
    Demand holder idiom is.
    So, back to question 1, is this thread safe?
    public class ServiceFacadeImpl {
        private Result1 result1;
        private Result2 result2;
        private static class LazyHolder1 {
            private static final Result1 INSTANCE = new Result1();
        private static class LazyHolder2 {
            private static final Result2 INSTANCE = new Result2();
        public Result1 getResult1() {
            return LazyHolder1.INSTANCE;
        public Result2 getResult2() {
            return LazyHolder2.INSTANCE;
        public static void main(String[] args) {
            ServiceFacadeImpl sfi = new ServiceFacadeImpl();
            sfi.getResult1();
            sfi.getResult2();
    }And question 2: Is there a way to implement a less restrictive lazy load approach without appealing to static inner classes? I would love to cache Result1 and Result2 as ServiceFacadeImpl instance variables instead of static inner class - static variables lol).
    Inner Enums are cool, but as you told me, they are implicit static, plus the
    public enum SomethingFactory {
      INSTANCE;
      public Something createInstance() {
          return new SomethingElse();
    } approach don't work since newSomethingElse() (that represents heavy computation) will be called every time.
    I could use a enum Constructor Approach like this:
        public enum Factory1 {
            INSTANCE;
            Result1 result = new Result1();
       public enum Factory2 {
            INSTANCE;
            Result2 result = new Result2();
       public Result1 getResult1() {
            return Factory1.INSTANCE.result;
        public Result2 getResult2() {
            return Factory2.INSTANCE.result;
        }I can't have a enum Factory holding all results because the constructors for all of its values are called at once... So I would have to mantain a lot of enums like enum Factory1, enum Factory2, etc, just like the static inner classes case. Lazy Loading a instance variable in a non restrictive / thread safe way in java is proving to be quite challenging.

  • I have always used Firefox to make Jibjab videos. Now after creating video it no longer previews or finalizes video. If I use IE everything works fine.

    I have gone through the Jibjab support site, tried all options they supplied with no success. All of my firefox plugins are up to date including flash, java and silverlight. This problem probably started 4 - 5 months ago. I can always go through IE, but IE is not my default browser. Also, once I make a new jibjab video using IE and finalize it, I can then use firefox to view that new video as well as all of my old ones created. It only hangs up when trying to create a new video. I get no error messages when trying to make a jibjab video. I add all my heads and when clicking on preview or done I basically get a blank page with only headers showing as if it is about to perform the next action but then just stops. It has only been on the jibjab site that I find this happening and they have not been able to solve the problem.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    '''Try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * You can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    ''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
    You can check for problems caused by recent Flash updates and try these:
    *disable a possible RealPlayer Browser Record Plugin extension for Firefox and update the RealPlayer if installed
    *disable protected mode in Flash 11.3 and later
    *disable hardware acceleration in the Flash plugin
    *http://kb.mozillazine.org/Flash#Flash_Player_11.3_Protected_Mode_-_Windows
    *http://helpx.adobe.com/flash-player/kb/common-problems-flash-player.html

  • Do ViewObjects have to be thread safe?

    Hi all,
    I'm implementing custom methods in a ViewObject, and I was asking myself if they have to be thread safe. I want to access some custom instance attributes in the custom method of the ViewObject. Do I have to synchronize the access to the instance attributes of ViewObjects?
    While we are at it. It would be interesting to know, which classes in BC4J get accessed by multiple threads at the same time, if any. If I understood it correct, ApplicationModule objects can be accessed by multiple threads simultaneously, if they get checked out statelessly.
    Thanks for any help
    Benjamin

    Benjamin:
    We synchronize calls into BC4J ourselves by sync'ing on the root AM. Thus, you shouldn't need to worry about thread safety for your custom VO methods.
    BC4J synchronizes accesses into root AMs.
    Even with all this, you need to worry about one aspect of multi-threading--garbage collector thread.
    If you implement a custom 'finalize()' method on your BC4J subclasses, you need to worry about the fact that the GC (garbage collector) thread may be calling finalize() in its own thread. This means the code path travelled by the finalizer should be thread safe.
    Thanks.
    Sung

  • SoftReference/PhantomReference idioms?

    Hi all. I'm finding myself needing to use SoftReferences to implement a memory cache.
    The trick is that I need to know when each object is garbage collected; I will serialize it to persistent storage and then deserialize it if/when it's needed later. In this case, the cost of recreating the object from scratch is sufficiently high that this approach makes more sense.
    Since I know other fellow travellers have surely trod this road before, is there a well-known idiom (dare I say design pattern?) for this?
    One option is to handle the serialization in the object's finalize() method. Are there any reasons not to do it that way (that's the direction I'm headed right now).
    Alternatively, I suppose I could also create a phantom reference as well, but even though I've read Bill Venner's chapter and Monica Pawlan's technical article (both excellent, by the way), it's not clear to me how that would be constructed. I need to the soft reference so that the JVM GC's the object when needed, but I need the phantom reference to get to the object before it's cleared.
    Actually, I was sort of surprised that when you associate a reference queue with a SoftReference, when you remove() the SoftReference from the queue, the pointer to the referent is already cleared. I don't really see what the use would be of a reference queue with anything but a phantom reference.
    Any suggestions, pointers, tips, etc would be greatly appreciated. Thanks.

    Well, it looks like I'm just talking to myself here, but I thought I'd relay what I discovered in tackling this problem.
    First, given the availability of Reference objects I don't think finalizers are the way to go. Other sources I've read seem to confirm this. The main issue for me is that serializing & saving the object to backing store is a non-trivial task, and it seems that by the time the finalizer is called, the JVM could already be in a memory-constrained situation.
    The approach I've taken is to save a copy of the object to backing store fairly early on in its life, so that when the GC wants to reclaim it, there's nothing that needs to be done.
    Works like a charm.

  • Is this code thread safe?

    I've been seeing some information that makes me think that some servlet code I have that I thought was thread-safe actually isn't. I have a servlet that takes a POST request and calls a stored procedure on a database to do some inserts.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
      // Check validity of request then proceed.
      if (valid) { postPayment(request); }
    synchronized private void postPayment(HttpServletRequest request)
      /* Take some parameters from the request and call the stored procedure */
    }What I'm attempting to do is ensure that 2 requests with the same data don't attempt to insert to the database at the same time. Have I accomplished that or do I need a different approach?

    Meatwad wrote:
    What if I had a static synchronized java bean that a member variable of the servlet class?As stated in my previous post:
    even that wouldn't be enough if there's more than one server running your app.and
    Since it database operations that you want to make atomic, the right place to ensure that is in the database.and
    The database is the only place where you're guaranteed a shared point of access to the resources you're trying to protect, so that's the appropriate (only) place to provide that protection.For an academic exercise with a single server, and if no other servlet or app is modifying the relevant tables, your approach is probably sufficient. But when all is said and done, a database transaction is the appropriate way to ensure exclusivity and atomicity of database operations.
    EDIT: Now, when you say "java bean", if you in fact are referring to an EJB, then I think they have their own tools and idioms for exclusivity and atomicity that encompass Java level syncing and DB transactions. I'm don't know anything about that though.
    Edited by: jverd on Jun 22, 2011 10:23 AM

Maybe you are looking for