Static initializer is called twice

Hi all

This is my first post here, I'm new to Java and BB development as well.

I'm developing an application multi-threaded data are exchanged between threads using classes containing only static members private and public accessors where access to private members are synchronized.

It looks like this:

public class GPSData
{
    private static double _latitude = 0; // degrees

    ...

    private static Object _latLock;

    ...

    static
    {
        _latLock = new Object();

        ...

    }

    public static void setLatitude(double latitude) { synchronized(_latLock) { _latitude = latitude; } }
    public static double getLatitude() { synchronized(_latLock) { return _latitude; } }

...
}

Here, the GPSData class is never instantiated, the static block is used to create the lock. For some discussions, citing getLatitude may involve another block static call and the return value is the value intialized. It behaves as if it were another "instance" of the class. For some other discussions, it works fine, good value is read.

Someone has an idea?

Welcome to the forum and the development of BlackBerry.

You hit the first of what I think will be a few quirks of BlackBerry, at least they seem weird at first.

A static is NOT a SIngleton.

It is in the case when you have only one Application accessing static data.  If you have multiple Applications accessing the same code, you will get several static variables (which means initialize static multiple tracks of code).

I guess in this case you have a background Application and a foreground app, or maybe you access that a listener or ApplciatinMenuItem.

In any case, the solution is to use RuntimeStore as shown here:

How - to create a singleton by using the RuntimeStore
Article number: DB-00686
http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How_to _...

Tags: BlackBerry Developers

Similar Questions

  • CreatePanelHook called twice? !

    Hi all

    I noticed a very strange behavior of the call to CreatePanelHook .

    Just after my plugin with AE CC 2015 test, I met in a very strange behavior with AE CC 2014.

    When I opened my control panel from the menu, the function 'CreatePanelHook' called twice. However, if the Committee was already opened in the previous execution of After Effects, the "CreatePanelHook" called only once.

    Any ideas why that may happen? How can I avoid this?

    Best regards

    Yuri

    Hi kotuk81,

    I'm just running on this problem today. In my case, I found the problem, is that I forgot to do my menu command has been treated in my menu command hook. Here is the code of the sompe, I hope I can help,

    VS_ETX (_suite_h-> RegisterSuite5()-> AEGP_RegisterCommandHook (_plugin_id,

    AEGP_HP_BeforeAE,

    _menu_command,

    & _menu_command_hook_s,

    (AEGP_CommandRefcon) (this))) ;

    public static void menu_command_hook (AEGP_Command command,

    AEGP_HookPriority hook_priority,

    A_Boolean already_handle_b,

    A_Boolean * handle_p_b)

    {

    If (control is _menu_command)

    {

    VS_ETX ((*_panel_suite_p)-> AEGP_ToggleVisibility (_match_name_z));

    * handle_p_b = TRUE; DON'T FORGET MARK IT AS MANAGED<>

    }

    }

  • initializer, instance and static initializer blocks

    Hi guys,.

    I have read the foregoing, mentioned in the JLS and also in a book before, but I still do not understand, what is the use of these. I have sort of a rough idea, but not exactly. I mean, what is the purpose of the initializer for instance and static initializer blocks, how can be useful? I understand that I can run pieces of code that initialize instance and static variables accordingly, but what is the difference then to use a constructor to initialize these areas? Are these pieces of code executed before the execution of any manufacturer, or when otherwise?

    Sorry for my noob, I learn.

    PR.

    Static initializer blocks are executed when the class is loaded, once (a classloader). So that they have some use. Initializers for instance differ a lot of builders (I think that code in the initializers of the instance has been copied to each manufacturer), but they can be useful with anonymous inner classes for example (since you cannot define constructors it (well, you can, but you can't call them)).

    They have a limited use, but it is good to recognize them if you see them.

  • Aggregate() called twice on each node

    Guys,

    I do not see aggregate() method is called twice on each node for the same call, I do not understand why? First aggregate() is called without passing all entries at all and the second time his name with entries corresponding to the filter. Why is it called twice on every single node?

    I was under the impression aggregate() will be called once per post with all the data that matches the filter and aggregateAll() will be called once on the client proxy / invoking the aggregator.

    No indication in this will be helpful.

    Thank you

    K

    Of filter function (including aggregation based filter) are processed in batches by using single thread. Batch could be any number of partition (from1 to all partitions of opportunity).

    The deserialized cache entry are kept in memory until the batch is completed (i.e. the filter may require the deserialization and aggregator later may require deserialization too).

    If entire cache must be processed in a single batch, he trained under high memory pressure, so consistency is divided into several lots.

    First batch is usually a partition, it is used to estimate the memory pressure by partition for request and choose optimal number for other lots (often you will see exactly two lots - single partition, then the rest of the partitions).

    Each batch is separated aggregate() call (or processAll() in the case of input processor).

  • Action to the 0ms within the symbol is always called twice

    Roadside animate 2014.1.1:

    I wonder if its normal behavior that an action that I put to 0ms on the timeline of a symbol is called twice (sometimes even more often, but I do not know why) when I start the animation.

    See http:www.pixelsymbiose.de/devpix/testing/test.zip for an example.

    a single symbol with two grafics and an alert to 0ms on the scenario of the symbol.

    This is a bug, only latest version.

    You can move your trigger from 0.00 to 0.05

    See: playReverse() relaxation

  • The ADF workflow initializer is called before after the settings?

    My workflow has several parameters, some of which are optional.
    It is not clear in what order are called methods set for parameters, nor is it appears from the documentation that the initializer for a workflow is called before or after the set methods for parameters of the workflow are called.
    I want to call a method, once all parameters have been set. I can do this with the initializer?

    They must be defined at the same time that the initializer is called. Oracle guarantees not the order in which they are defined and customer should not count on that. If you are interested in looking under the hood some more watch this blog post:'t-fit-all.blogspot.com.au/2010/10/jdev-programmatically-capturing-task.html http://one-size-doesn

    If your end goal is to call a method once the parameters are defined, simply include a call to the method as a default activity in your workflow. It is usually my preference when I don't want to make the programmer next abreast of all treatments applicable to the main object of the workflow. The previous link is the exception, as it was written for purposes of logging, and my preference is not to clutter the workflow with logging code.

    CM.

  • called twice

    Hello

    What happens if your script is called twice?

    If you have a script that creates a palette to dial 1. On call 2, your code determines that the palette is already displayed, calls a routine and returns without creating the palette. In my case, appeal 2 we look at some parameters that determine not to display the palette.

    Are there in fact two copies of the script running? What heppens to all memory allocated in call 2. Is it safe to keep calling the same script in and out that we call 2.

    Is there documentation on this thing of the kind.

    Thank you.

    P.

    Hi Pickory,

    When you run a script in an engine persistent (i.e. any targetengine which is not 'main'), the global scope (i.e. so, or $.global) manages its data in memory once the script has completed, so that all global variables / references are kept to next run. (On the other hand, the 'hand' engine automatically kills references.)

    A quick test to verify this fact:

    // ==================
    // Run this script twice
    // ==================
    
    #targetengine "test"
    
    var arr, obj, func;
    
    if( 'undefined'==typeof arr )
        {
        alert( "Defining arr" );
        arr = [1,2,3];
        }
    if( 'undefined'==typeof obj )
        {
        alert( "Defining obj" );
        obj = {foo:'bar'};
        }
    if( 'undefined'==typeof func )
        {
        alert("Defining func");
        func = function(){alert( "Hello World!" )};
        }
    
    alert( [arr,obj.toSource(),func.toString()].join('\r') );
    

    As you can see, global arr, obj, func variables are always there when you rerun the script, and you don't need to set them again.

    Note that the script itself is not stored in the engine of 'test '. The code is always fully interpreted when you execute it, and you can run another script in the same engine. Therefore, you see a motor continued as a "space of memory" expressly attributed to your task and which persists throughout the InDesign session.

    What happens if you reset again and again the same global data, for example:

    #targetengine 'test2 '.

    var a = [1,2,3];

    etc.

    Theoretically, this leads to potential memory leaks, as every time that the script runs that the existing content of the table is lost without deallocation because a new one is created. Fortunately, the mechanism of 'garbage collector' is treated as a background task for the old references are supposed to be cleaned. However, there is a performance cost obvious recreate permanently and power of complex data (tables, objects, functions) that already exist. This is why it is advisable to check if global vars are already defined. Some of them are not intended to vary, while others may require to be updated when the context changes. When a persistent engine script becomes complex, a usual programming model is to write a routine global charger as follows:

    #targetengine "test3".

    var loaded;

    If (! support)

    {

    creating and feeding the global vars

    load = 1;

    }

    your script here

    Hope that helps.

    @+

    Marc

  • CreationComplete event handler called twice in the customized for TileList item converter

    I have a TileList component with a component converter custom:

    < mx:TileList

    id=" _imageList " " itemRenderer =" com.technificent.renderers.ImageTileItemRenderer " " > "

    The ImageTileItemRenderer is a component MXML that indicates a creationComplete handler in the root tag:

    < mx:HBox

    ' xmlns:mx = ' http://www.Adobe.com/2006/MXML " creationComplete = "initComponent () '... '"

    The problem is that initComponent is called twice for some reason any.  The following code inserts into initComponent:

    public function initComponent (): void

    {

    trace (_someStringMember);

    _someStringMember = "test";

    }

    results in the following:

    null

    null

    No idea why this is happening?

    Thank you in advance for your help!

    Moshe

    The TileList emit a hidden converter used to measure, to determine the size of the tile.  As renderers can be recycled, assuming that the number of events you will get probably isn't a good idea.

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

  • A button to push causes endpoint to call twice the MCU

    Hi, I have a problem with the TMS conferences that use the type of button to push a connection. When the ends are the meeting quickly reach, I select join and end points, then dial conference number twice at the same time. This starts a video call and an audio call at the same time, causing an echo. If you hang up the audio call the Conference continues normally.

    Can someone shed light on how the meeting gets setup of TMS or advise what opens a session for further investigation.

    I have v8.6.2 CUCM, VCS - c v7.2.2, TMS v14.3.2 and MCU 5320 v4.4. All the end points are saved to CUCM. Manual and automatic calls all work well.

    Thanks in advance

    Hi Ian,

    Above problem is a known, documented bug in CSCul80930.

    This has been resolved in version 7.1 of TC. You can go to TC 7.1.1 version on your codec.

    http://software.Cisco.com/download/release.html?mdfid=283644997&flowid=2...

    Kind regards

    Amit

  • Java program will not work in his development directory

    I have a 12 years/applet program that is on the web for 12 years. It's an interactive color wheel:

    * http://r0k.us/graphics/SIHwheel.html

    My development tools are a nice text editor and the JDK. No IDE is involved.

    I'm doing a major update, which shows the names of the closest color to a database of the names of 1 567. I wrote it so it can run as an applet or program, and it works beautifully in the development directory. However, when I move the jar anywhere else, the following error appears:

    D:\progming\temp > java SIHwheel
    Exception in thread "main" java.lang.NoClassDefFoundError: SIHwheel
    Caused by: java.lang.ClassNotFoundException: SIHwheel
    in java.net.URLClassLoader$ 1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged (Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    to Sun.misc.Launcher$appclassloader$ AppClassLoader.loadClass (Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    The main class is not found: SIHwheel. Program ends.

    The file I'm running is SIHwheel.jar. To further complicate things, TI sorting only works as an applet. Main elements of the canvas are missing, like the preset itself. So 3 cases:

    (1) directory of the part: works beautifully as a program
    (2) another directory, fails as program
    3) run as an applet, highly degraded operation

    This used to work fine, any where, as a program or an applet. There are two fundamental differences about what I did before.

    (1) the new ntc.class has an own main() (essentially for the test and demo for developers who can use it). I don't think it's a problem, because I have a jar manifest by declaring that the class has the main() I want to run.
    (2) above, all classes comes from the SIHwheel.java file. However, ntc.class is from the ntc.java file. All classes are jar'red in SIHwheel.jar, however. Since ntc.java implements the functionality of the script ntc.js (name as color), and I want to share it, to keep this as a separate file.

    I include a manifest file in the jar and, from the unzipped pot, the MANIFEST file. MF displays a line from the Main-Class: SIHwheel

    What's not?

    No, the main method is not called when you run a cmdlet (only when run as an application). See the Applet tutorial [url http://download.oracle.com/javase/tutorial/deployment/applet/subclass.html] (note that the example he use Swing and you use AWT).

    A static initializer is called when a class is loaded. If do you the private init() method and make sure it is called when someone uses the class with:

    public class NameThatColor {
      private static float[][] rgbhsl;
      private static final String names[][] = { .. }
    
      static {
        init();
      }
    
      private static init() { ... }
    }
    

    Note that the static variable are reported before the static initializer and nothing else should call init();

  • problem with static bitmap initializer

    I migrated my main current project of the JDE to Eclipse + plugin now (since we created a script of maven that copies of our class in the project library, it is possible).

    I use a utility class to initialize all the images I use private constructor and only static members.

    However, none of the images is correctly initialized.

    Here is the code for the BitmapProvider class:

    public static final EncodedImage BUSINESS_INDICATOR_24 = EncodedImage.getEncodedImageResource("symbol2424.png");
    

    to debug, I create the same static image on TIME. This method works correctly.

    encodedImage is well settled, however, BitmapProvider.INDICATOR_24 is not.

    EncodedImage encodedImage = EncodedImage.getEncodedImageResource("symbol2424.png");
    ApplicationIcon indicatorIcon = new ApplicationIcon(BitmapProvider.INDICATOR_24);
    

    I do not have ANY code change, the static initializer to work properly in the JDE.

    To the nth attempt the debugger is entered in the static code (so it is executed).

    The culprit was the overview of the application icon.

    After a few experiences and shamanic tips of my colleague about something similar two years ago, I removed this icon of the application descriptor.

    And now it works.

    Quite strange, the normal application icon is recovered in the static method, if an icon is marked as Overview icon in the application descriptor that it cannot be used in the application more.

  • In Windows 7, I can send and receive faxes but when someone calls they hear static fax

    Hello. IN WINDOWS 7, I CAN SEND AND RECEIVE A FAX, BUT WHEN SOMEONE CALLS ON THIS LINE AS A PHONE CALL, THEY HEAR FAX STATIC AND CANNOT CALL VIA.  HOW TO ELIMINATE THIS WHEN I RECEIVE A CALL REGULAR ON THE SAME LINE?

    As previously stated the feature seek you, IE automatically switch the call fax or phone to answer, depending on the type of appeal are not a feature of win7 or any fax modem.

    There were external devices, you can buy separately put the call to the fax or phone depending on the type of call received.

    Personally when I had only the line I would activate only the fax when I received a call that was an incoming fax. IE, hang up the phone, and then activate the fax. Of course this works if you are in the unit.

    Its probably easier to get a fax to e-mail service, assuming that you do not want a second line.

  • SelectOneChoice: valueChangeListener called that one only twice

    Hello.

    My version of JDeveloper is 11.1.1.7.0

    I drag and drop a notice from the DataControls, as a SelectOneChoice (SOC).

    My question is valueChangeListener (vCL) is one called twice. So, I change the value of the COS and vCL is called and works well, then I change the value new and vCL is not called. Then I change again and vCL is called, then no, then Yes, then no... and so on.

    What could be the problem? Here's the code SOC and vCL

    <af:selectOneChoice value="#{bindings.MyTableView1.inputValue}"
                        label="My label"
                        shortDesc="#{bindings.MyTableView1.hints.tooltip}"
                        binding="#{backingBeanScope.myBean.soc7}"
                        id="soc7"
                        valueChangeListener="#{backingBeanScope.myBean.myListener}"
                        autoSubmit="true"
                        valuePassThru="true">
      <f:selectItems value="#{bindings.MyTableView1.items}"
                     binding="#{backingBeanScope.myBean.si14}"
                     id="si14"/>
    </af:selectOneChoice>
    

    public void myListener(ValueChangeEvent event) {
        event.getComponent().processUpdates(FacesContext.getCurrentInstance());
      
        JSFUtils.setExpressionValue("#{bindings.MyTableView1.inputValue}", event.getNewValue());
      
        Integer resultAttValue = (Integer)JSFUtils.resolveExpression("#{bindings.MyTableView1.selectedIndex}");
      
        // My stuff...
      }
    

    Any ideas would be very useful.

    Thanks in advance. Best regards

    Finally, he worked creating the SelectOneChoice of an LOV.

    There is an id attribute, which includes descriptions in the main view, other opinions.

    Creating a LOV for the attribute id and drag and drop to this id works.

    When I associate the listener in my question, that works very well. Otherwise, I Don t know why, but it does not work well.

    Finally, as Jacques has said, valuePassThru is not necessary. Thank you.

    I hope this helps.

    Concerning

  • ButtonSkin call measue() twice when the icon is used

    Maybe I'm missing something, but it seems that the default value as the Spark ButtonSkin.mxml eventually Measure [] call twice every time that an icon is used.

    Also, last time I check the value by default than panelskin. MXML eventually call updateDisplayList() twice every time the 'borderVisible' property is displayed/hidden.

    Supposed to be a bug has been saved for the second. With all the talk about the optimization of performance lately, I would have thought that these things could have been watched in the now...

    Loaded external icons loaded a frame later (or more, as they are)

    loaded asynchronously).  Therefore, when the button is first created and

    measured, is not a made-to-measure and later icon when the icon is

    happen, it must measure again.

  • Extend the rights of the player causing the Initialize event of draw twice?

    I have a few boxes, populated by scripts on their respective initialization events. Everything worked very well through development - except when I took the form of a group, I noticed that the drop-down lists were filling twice. I didn't was not using a clearItems () - should not need, right?

    So, it was something that I couldn't reproduce in decorator. Once the extended rights had been removed, the form executed as provided in Acrobat and Reader, too. Put the extended rights, and drop-down lists are double to fill in again. Take off extended rights, no misconduct, everythings fine. Extended rights on, bad dog no biscuit!

    Now, obviously I can get past this by using clearItems(), or by moving the preOpen scripts. However, I would like to know what the heck is the cause? Is this a bug? a known issue? or is it something caused by something in the form? I always assumed forms behave the same with or without extended rights. But it looks a lot like the Initialize triggers event twice when opening with extended rights.

    Any ideas out there?

    Thank you

    Stephen

    Hello Stephen,

    I encountered this before and thought that I had an "appropriate" response, but I'm not. I think that when player allowing the rights are applied by Acrobat form performs a check as part of the logon process. There seems to be a bunch of events that triggered twice when the form is active player (in Acrobat - I can't test if the form is activated in LC RE ES2).

    Here is an example showing how, when and in what order, events fire.  The form is at the end of the post (at http://cookbooks.adobe.com/post_How_often_events_fire_and_their_sequence-16547.html). There are 13 items in the form, the events are followed.

    When the form is not activated start looks at this (some events fire once as expected):

    When I apply the reader by activating rights via Acrobat, triggering events double for:

    • commissioning;
    • form: ready;
    • layout: ready
    • IndexChange;
    • docReady.

    An indicator of potentially, what happens is that, in the RE version, the preSave event fires (but not postSave event).

    Not the complete answer - just an indication.

    Good luck

    Niall

Maybe you are looking for

  • What is the speed of the hard drive of the 2015 2 and 3 to merge disks partition?

    I was looking through the Apple site and was wondering about the speed of the drive in the iMac in car merger. On their site it says that the 1 TB Fusion drive has 24 GB of Flash memory, and 2 models to and 3 to have 128 GB of Flash storage. But it d

  • Unable to open Windows Media Player

    Hello I have XP Home Edition on a quite old Dell computer.  When I try to open WMP, I get the following: computer Log off and then log back. This notice did not help at all.   I used WMP for video CD last week and it worked. Thank you Mike

  • What is the fastest way to update to Windows XP?

    original title: I need to update a computer that have not been updated since 2008. How can I do without going through the long process of the computer looking for available updates? It's Windows XP. I had changed our PC and it has been stored. I had

  • Cannot enter spaces between words in the Message Outlook Express rule

    I had to re - set up of operating systems Windows XP Pro on top of the existing system without reformatting the hard disk. Now, I noticed that when you create a new message rule, I can't enter a space by the shift to separate words in entry for examp

  • mp3 player Archos is not no detectored at all on windows xp 2009

    a archos mp3 player, device dector Player do not recognize it at all, nothing when pluged into usbports, the ports are working properly I checked the pen drivers and they charge ok but nothing to do with it. I have a windows 7 vista 2009 I gotlaptop