Need help on concepts of threads

Hello! I need your help on some concepts related to threading, implemented in the J2ME.

I have a file which is a singleton, and executes the actions in the order in which they are stacked.  Everything works well, but sometimes, I have to do an operation on the queue.  Set some variables with a value of internal audit.  It is here that I found the problem.  Even if my class is a Singleton (I checked, it's really a singleton), I have 2 different instances of my class.  Who is "managed" by a background thread, the other by the interaction of the user interface.

How to synchronize these 2 objects in one? I absolutely need my background thread to use the same queue like everyone else.

Here is a version stripped of my Singleton:

package ca.victrix.sp.synchronizer.action;

/**
 * Class used as a queue of different work processes
 * @author slevert
 *
 */
public class WorkQueue
{
    private final PoolWorker thread;
    private final LinkedList queue;
    private static boolean networkActivated;
    private static WorkQueue workQueue;

    /**
     * Gets the one and only instance of the queue
     * @return WorkQueue
     */
    public static WorkQueue getInstance() {
        if (workQueue == null){
            synchronized(WorkQueue.class) {
                WorkQueue inst = workQueue;
                if (inst == null) {
                    synchronized(WorkQueue.class) {
                        workQueue = new WorkQueue();
                        workQueue.setNetworkStatus(true);
                    }
                }
            }
        }

        return workQueue;
    }

    /**
     * Sets the network status
     * @param activated
     */
    private void setNetworkStatus(boolean activated) {
        networkActivated = activated;
    }

    /**
     * Gets the network status
     * @return boolean
     */
    private boolean getNetworkStatus() {
        return networkActivated;
    }

    /**
     * Private constructor
     */
    private WorkQueue() {
        queue = new LinkedList();
        thread = new PoolWorker();
        thread.start();
    }

    /**
     * Executes the actions by adding them to the linked list and by notifying the queue of the change
     * @param runnable
     */
    public void execute(Runnable runnable) {
        synchronized(queue) {

            if(!getNetworkStatus() && runnable instanceof WorkRecoverable)
                queue.addLast(runnable);

            if(getNetworkStatus())
                queue.addLast(runnable);

            if(getNetworkStatus())
                queue.notify();
        }
    }

    /**
     * Activates the queue
     */
    public void activate() {
        this.setNetworkStatus(true);
        synchronized (queue) {
            queue.notify();
        }
    }

    /**
     * Suspends the queue
     */
    public void suspend() {
        this.setNetworkStatus(false);
    }

    /**
     * Check if the network is activated
     * @return boolean
     */
    public boolean isNetworkActivated() {
        return networkActivated;
    }

    /**
     * Private class used to pool the threads
     * @author slevert
     *
     */
    private class PoolWorker extends Thread {

        /**
         * Runs the action
         */
        public void run() {
            Runnable runnable;

            while (true) {
                synchronized(queue) {
                    while (queue.isEmpty() || BlackBerryCore.getNetworkCoverage() == CoverageInfo.COVERAGE_NONE) {
                        try
                        {
                            queue.wait();
                        }
                        catch (InterruptedException ignored)
                        {
                        }
                    }

                    runnable = (Runnable) queue.removeFirst();
                }

                try {
                    runnable.run();
                }
                catch (RuntimeException e) {
                    execute(runnable);
                }
            }
        }
    }
}

Thanks in advance!

Think that you have fallen into one of the traps BlackBerry.

A static is NOT a singleton.

You will get different instances of static variables for various startups, so your GUI and your automatic boot process will have different static.

If you are not persistent data, the best place for this is RuntimeStore.  Read the following Article.

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

  • Need help for testing and practice the concepts of the server at home

    Original title: Hello team

    I need assistance with testing and to practice the concepts of the server at home... I don't have an option to test laboratory pls suggest possible ways that I can practice... need help... Please help

    Hi Sachinadi,

    You can ask your question in the MSDN Forums: http://msdn.microsoft.com/en-us/hh361695.aspx

    Thank you.

  • Computer laptop touch screen 15: need help - restore Partitions, OS system, start-up and drivers!

    [Need help]

    Device name: laptop touch screen, Energy Star, 15.

    Model number: 15 - f023wm

    Device status:
    [Grandma] "I broke the internet.
    [Me] "No, I have demolished just any chance I had as a computer programmer.
    I'll never do it to heaven now... »

    You want to come: difficulty this laptop!

    -Packing plant (Reset/retrieve)

    -Retrieve/Re-restore boot loader

    Retrieve/recreate/Re-restore all original scores.
    -Retrieve / Re - restore all the Original system & hardware drivers.

    -Retrieve/Re-restore Windows 8.1.

    -Possibly find computer Tech/Geek fellow/Pal.

    -Learn something new! (Not including the common sense).

    Explanation:
    -J' was too high as he tried to become the next Bill Gates and create a calculation method in which the processor completely laws of physics bi-passes.

    Topical issues:

    (1) I have little experience, I'm sure compared to most of the users on this forum; However, in the College computer Programmning.

    ---> Very adept in acquireing newly introduced information & request a great sense of understanding of puzzled, abstract and largely serious concepts. (It will be just a little easier than most to explain a simple fix).

    (2) I deleted all partitions, including the system files, System opperating, some methods of starting, all the drivers, and to add to the mess, the existing partitions are not yet check the size or formatting - I'm sure.

    ---> (Drive C is 400 GB;) Drive D is the main partition with only 20 GB)

    (3) any chance of installation/download are only feasible when my boyfriend does everything it does and 'fixed' the laptop.

    ---> Cell phone MAY start, can use internet and MAY be able to download 5 pictures before the system shuts down and the other requires a few hours to wipe the minimum amount of space on the hard disk before you reinstall Windows.

    (4) Windows 7 is the only OS (so far) that we are able to install; We have no other disks, but Windows 8.1, I think, was the original Opperating system and look forward to this return.

    (5) I don't know yet how I will receive notification here on these forums. I'm drunk at 05:59, so I'll find out tomorrow.

    ---> Assuming that I remember I wrote it.

    And I think that's all that I need a little help with if you want messages me or live chat to help solve this problem, I think that Skype is aloud; and in all the uncertainties, it is listed on my profile.

    Thank you, & your best.
    Caleb D. Parker
    @CiDiParks25

    CiDiParks25

    What will work restores your computer to its original factory state using HP recovery media.  It is a DVD and CD set that will erase the hard drive (removing all data, applications and settings, reinstall the original OS, drivers and utilities for HP. In some cases, you will be able to order a USB instead of discs.  You must order at HP; they cannot be downloaded.

    The link is on the software page and download drivers for your PC: http://support.hp.com/us-en/drivers/selfservice/HP-15-Notebook-PC-series/7137590/model/7484025

    Once there, scroll to the bottom of the page and you will see an entry for the command Recovery Media-CD/DVD/USB. Click on the symbol '+' to expand this entty and click on order to press for more details.

    Or, if you prefer, you can do the same by contacting HP Customer Service:

    If you live in the United States or the Canada, details are on this page: http://www8.hp.com/us/en/contact-hp/phone-assist.html#section1

    If you live elsewhere, contact details are on this page: http://www8.hp.com/us/en/contact-hp/ww-contact-us.html

    Note that if HP no longer provides a recovery media for your model, a few other sites, you can check are: http://www.computersurgeons.com/ and http://www.restoredisks.com/

    Don't forget to read through the material in the linked thread before attempting the recovery: http://support.hp.com/us-en/document/c00707939

    Good luck

    I'm a volunteer and I do not work for, or represent, HP.
    ========================================================================
    If you feel that my suggestions helped you, please click on the thumbs-up symbol to say thank you!

    If they helped to solve your problem, please click 'Accept as Solution' to help others find similar information.

  • Need help with settings - wifi extension

    So I need help from networking. I have xfinity for my internet with a router/modem from arris tg1682g. However, it is located in a horrible place. So I run Ethernet to a central point and connected to an AirPort Extreme (latest version). Extreme, I ran Ethernet in the basement and connected a first gen express. I also have a second express gen located in the rooms upstairs.

    the extreme and express it is defined to extend the network, however the signal keeps a fall or be slowed down significantly even when you are inches apart. When I got the arris in bridge mode and the extreme to create the network and expresses it to extend everything worked fine. However, we have the security to the House installed xfinity, and they took the arris off mode bridge because they do not allow me to use the extreme for the security system. Since then, I got nothing else problems with my internet connection. It is either significantly reduced performance (up to 18mbps 150mbps).

    I also get error messages that the network is not found on the airport connected Ethernet devices.

    It has been very frustrating because the people Comcast it is horrible. So, any help would be greatly appreciated. Thanks in advance.

    https://discussions.Apple.com/message/29878786#29878786

    https://discussions.apple.com/thread/7195783 - is it possible to use the apple Time Capsule as a range extender?

  • Blu error screen! STOP 0X000000F4. Need help.

    Hello.

    I have this laptop with win 7 installed. It worked fine, until I did an o procceses with cleaning TuneUp2009. (I do regularly each month and it is ok) but now after tuneup2009 restarted my pc, start it shows this stop error message. STOP 0X000000F4.  I tried the mode safe but is impossible access, the same error code. I tried to format my pc with a disc of win7, but always without success, it seems that the pc does not boot from the cd room (I changed on the bios Setup boot order).

    And now need help

    Thank you.

    Hello.

    At has first of all thanks a lot for your help.

    I solved my problem in this way.

    I removed my hard drive to laptop, took all the documents I did not wont to lose and formatted it from another pc.

    I downloaded the first file its ( http://www.w7forums.com/threads/official-windows-7-sp1-iso-image-downloads.12325/ )

    and created an installer of the USB bootable Windows 7 on my drive with this tool ( http://download.cnet.com/Windows-7-USB-DVD-Download-Tool/3000-18513_4-10972600.html?tag=mncol;1 ) usd

    I have insterted my hard drive and my lap top when I started upward, I boot it form my USB stick and istalled win 7.

    Now it works very well. Just reinstall my programs.

    Thanks for your help once again.

  • I need help with an installation failure to interpret and troubleshoot a Setup log.

    Background: A few years ago, many editors of cinema used Final Cut Pro 6 (also contained in Final Cut Studio 2) for their editing projects.  Shared Apple Final Cut X uses a different format that is not compatible with FCP6.  Sometimes, these editors are called to work on a few historical projects that have been published in FCP6 and need this version to run now.

    Starting with OS X Lion, FCP6 would install not in Lion and thereafter.

    According research by Jeremy Johnston as noted on his blog, he discovered that Apple has inserted a file in the folder CoreServices in the Library folder of the system folder that causes versions the version Final Cut Pro X (and other older Apple programs in the same situation) do not settle.  He suggested changes to this file that would seek to prevent interfering with the installation of FCP6 in Lion, many users of final cut PRO 6 were successful in their efforts to install in Lion and work with it.

    Later in a discussion update on installing FCP6 in Mavericks, HawaiianHippie determined that the simplest way to perform the installation of FCP6 was simply copy this file and remove it from the system folder, install FCP6 and then restore the copied file:

    https://discussions.Apple.com/message/26309669#26309669

    I used this method with success to install FCS2 in Yosemite:

    [click on images to enlarge]

    However, in my attempts to install FCS2 in El Capitan, it fails in the last 5% to install the first DVD:

    First of all, I need advice on how to display an extremely large Setup log in this thread (on MacRumors, it is a method to insert a 'code' in a small box that can be the object of a scrollbar if necessary to read all along).  I am unable to find such a method to post here.

    Then once approved, I need help to determine which component is causing the installation to fail and perhaps this element can be omitted from the installation:

    If this element is not required, then maybe FCP6 can be installed successfully without it.  And if that omitted element is necessary, perhaps a manual method to install it can be determined by pacifists.

    It is my goal to help those who need to install and use FCP6 on their new Macs running El Capitan.

    Here is the post on MacRumors with pre-installed Setup log:

    http://forums.MacRumors.com/threads/i-need-help-with-an-installation-failure-to-interpret-and-troubleshoot-an-Installer-log.1954786/#post-22541389

  • DV7-7333 CL. : need help formatting has replaced hard drive in my laptop

    Greetings,

    I received instructions from HP another volunteer on a bad hard drive replacement. I replaced the hard drive with a new and need someoe to please guide me how to format my new drive hard back to the WIN 10 I had installed on the former. I also buy a 22 pin adapter usb to SATA.

    Another agent said that Windows 10 can be reinstalled on a new drive hard if your installation has been activated before. The activation servers Microsoft just know your computer and will be reactive. You must Access the media creation tool and have it make a bootable DVD player or you need a usb thumb drive at least 4 GB.

    I am in Germany but still do not know the language well enough and could not find a tool for creating Windows Media version in English free repacement.

    I don't know what to do to format my new hard drive... Please help!

    Thank you.

    Wes

    PROBLEM SOLVED (FINALLY)! I just wanted you to know that we have finally understood why the data on the computer with the media to WIN creation tool not was not download on thumb drive = Firewall! Not sure if everyone will have this problem but in collaboration with Windows agent, I happened to see a pop-up window saying something on the analysis of data not allowing not to download. It is therefore sometimes necessary to temporarily disable all firewalls and Web titles before starting the download.

    Follow the instructions of man Las Vegas thread above to create a bootable USB Thumb Drive to replace newly hard drive with OS Windows 10. HOWEVER, the following was not mentioned in his instructions, and not all computers can do this extra step so keep the following in mind if your USB key does not complete the upload.

    Again, to download data, I downloaded on the work computer, a USB key, I had to we need to temporarily disable all the security features on the work computer until you have completed the download of the WIN Media Creation Tool on the thumb drive process (this includes your private web anti-virus, we can use AND/OR the WIN Firewall and other security features available on the led computer. )

    I hope this helps those who have similar problems.

    Thanks again for all your help man Las Vegas thread!

    Kind regards

    Wes

  • Need help with loops

    Hi all

    I am a beginner in Labview. If need help in loops. Please check the attached vi and suggest me the procedure I followed is effective or not. If this is not the case, correct me.

    Waiting for answer

    According to the commentary of diagram, table sizes are all 16, then here is everything you need:

    (Hmm, clips chiseled Booleans in the constant diagram, just ignore that)

    "Elements of an array AND" checks if all a real (upper thread)

    'The GOLD table elements' check if at least one is true. (all others)

  • Need help, trying to decipher my Panel event logs control for security and applications.

    Hi, I need help trying to figure out how to decipher my control panel the security event logs and logs application for account hacking.

    All the advice to learn how to see what who are normal and what is malicious?

    Occurrences of breach possible system, based on very high traffic for the opening of session and closing session and special privilege settings.

    Please notify.

    HP Pavilion DV9700 entertainment

    Windows Vista SP1 Home Premium 32

    I'll leave this thread closed, since I work with other people on another forum on this topic.

  • HP C4580 not scan to PC. I need help to configure my Netgear router please :)

    Hello

    I've read here, the threads that talk about this printer prints only not to or from a PC - my problem is that the C4580 go scan from my PC, but will not scan to PC.

    I found an answer from someone who has had the same problem earlier this year, but I do not understand what to do.

    Here's the answer:

    "I have ordered mine entering the settings from my router (Netgear) page and setting the built-in firewall rules. "The internal firewall was blocking the printer, I could print, scan using the computer, just could not scan from the printer to the computer.

    Also, I have a Netgear router, but could do with help on how to do the same thing as the person above.

    Thanks in advance for any help!

    Sorry, I don't need help after all

    It was not the router requires a configuration, it is the firewall that was a block that should be changed to "allow".

    My "all-in-one" now does everything it is supposed to do

  • need help to reactivate the windows 2008 R2 server?

    reinstalled the computer has not been reactivated, said: license limit is higher.
    call customer service, began just after 30 minutes of waiting and issue describing, then call completed. twice already.
    need help

    Hello

    The question you posted would be better suited in the TechNet Forums. I would recommend posting your query in the TechNet Forums.

    http://social.technet.Microsoft.com/forums/en-us/winserverfiles/threads

  • Installed PCHealth Software says that my wife was mandatory fixed for windows seven, $285 need help.

    Installed PCHealth Software says that my wife was mandatory fixed for windows seven, $285 need help.

    CrystalBall © SEZ...

    See:

    I received a phone call from someone who claims to have a Virus
       http://answers.Microsoft.com/thread/4489f388-d6de-416d-9158-0079764bb001

    [HOW] Avoid scams phone & other support Tech Cyber scams
    http://www.Microsoft.com/security/online-privacy/avoid-phone-scams.aspx

    [HOW] Avoid scams that use the Microsoft name fraudulently [phone & email]
    http://www.Microsoft.com/security/online-privacy/msName.aspx

  • Need help to install Vista Ultimate x 64 SP1 - error 0x800F081F - standard corrections do not work

    I have trouble getting Service Pack 1 installed on Windows Vista x 64 final.

    Current issue: SP1 does not appear as an update, and I have not yet installed.  Windows Update tells me that I'm completely up to date.

    History (memory, may be some errors):

    • Performed the new installation, including Vista Ultimate x 64 disk erasure (MSDN)
    • Updated to current with windows update
    • Installed Office 2007 Ultimate (MSDN) (don't know where update what happened)
    • Active Windows (could be a problem doing this after you install updates?)
    • Installed CPU usage, network, gadgets sidebar discs counter meter
    • Installed Live Family Safety
    • Installed Chrome
    • Installed Google Apps
    • Google Pack antivirus installed
    • Installed Google Earth
    • Attempted a manual installation of SP1 - fails with the error 0x800F081F
    At the present time, I can't get a manual of installation of SP1 to work, and Windows Update tells me that I am up to date.  -> System control panel tells me I'm running Windows Vista Ultimate, but does not list all service packs.  He also confirmed that the x 64 edition is installed.
    Steps for debugging:
    • Installed the drivers for the sound card motherboard
    • A ran complete chkdsk on drive to repair bad sectors
    • Ran the system file checker - find corrupted files, but can't fix
    • Journal CBS does contain no [SF] cannot repair the entries
    • Installed continues to update the system tool - tool does eventually make a update facility - who settle whenever I run
    System Information Link: http://www.filedropper.com/systeminfo

    [1] this is a new installation, so nothing has been pre-installed.

    [2] the only antivirus that was installed is the one that is included in the google pack.  I took it...

    [3] SP1 does not appear as an update

    [4] I'm strongly considering just clean wiping and [do a clean install]

    A1. If Vista was preinstalled on the computer when you bought it and you use the OEM disks (or hidden restore partition) to reinstall Windows, any antivirus free trial which initially is preinstalled on the computer will be reinstalled, but not valid.

    A2. You have therefore no anti-virus application installed. I see.

    A3. There are several prerequisite updates that must be installed before SP1 will be offered. See...

    Windows Vista and Windows Server 2008 service Pack is not available for installation via Windows Update
    http://support.Microsoft.com/kb/948343

    A4. Since you do not have an antivirus application installed, it would be your best bet. See...

    Cleaning a compromised system
         http://TechNet.Microsoft.com/en-us/library/cc700813.aspx

    Personal data backup (which none should be considered 100% reliable at this point) then format the HARD disk and do a clean install of Windows. Please note that a repair installation (upgrade AKA on-site) will NOT fix it!

    HOW to do a clean install of Vista: section "If you want to reinstall Windows Vista by running a new installation...". "ofhttp://windows.microsoft.com/en-us/windows-vista/Installing-and-reinstalling-Windows-Vista

    Once installed the clean, you will have the equivalent of a "new computer" in order to take care of everything on the next page before connecting the machine to the internet or one local network (i.e. other computers) otherwise and before connecting a flash drive, card SD or any other external disk to the computer:

    4 steps to help protect your new computer before going online
         http://www.Microsoft.com/security/pypc.aspx

    Tip: After completing the computer fully patched, download/install KB971029 manually before connecting any player external to the computer:http://support.microsoft.com/kb/971029

    NB: No matter what Norton or McAfee free trial which is preinstalled on the computer when you bought will be reinstalled (but invalid) when Windows is reinstalled. You MUST uninstall the trial for free AND download/run the removal tool appropriate prior to installing the updates, Windows Service Packs or IE upgrades AND BEFORE installing your new anti-virus application.

    Norton Removal Tool
         FTP://ftp.Symantec.com/public/english_us_canada/removal_tools/Norton_Removal_Tool.exe

    McAfee Consumer product removal tool
         http://download.McAfee.com/Products/Licensed/cust_support_patches/MCPR.exe

    If you need help, please start a new thread in this forum: http://social.answers.microsoft.com/Forums/en-US/vistarepair/threads

    Good luck!

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • Need help to install windows 7 Home premium on my mac.

    Ideas:

    • Need help to install Windows 7 Home premium on my Mac
    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    Remember - this is a public forum so never post private information such as numbers of mail or telephone!

    Installation of Win7 on a Mac has nothing to do with Windows Update. Please repost your question here rather: http://social.answers.microsoft.com/Forums/en-US/w7install/threads ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • can receive messages but can't send on outlook express, need help

    Was just good with this computer that uses windows XP and have added my name is outlook express account. Things were going along fine until it tries to send a response to a current e-mail was greeted with an error message "secure (SSL). ' No, Error.10061 Socket error #0x800CCC0E ' and my message is stuck in my Outbox. Am at a loss to know how this can be resolved and of course need help...

    Check: File | Work offline and in: reviews | Layout: uncheck the preview pane and you should be able to delete the message.

    The account is probably not configured correctly. Double check your settings and if you don't get developed, after back and say EU your e-mail server and send an error message in its entirety. You can left click on it to highlight then right click to copy and then paste in this thread.

Maybe you are looking for

  • IOS based App clock alarm question

    The beginning of alarm when you use iPhone at the same time, the alarm 'repeated' down turn when you press OK. This cause of evil that I only expect it to be off before today and continue the next day. (This is not the case when press OK on the lock

  • Can't watch youtube videos

    When I try to watch a video on youtube it says "an error has occurred. "Please try again later". This only happens in youtube. I can watch youtube videos on Chrome. I have adobe flash player and firefox updated. In fact I just changed my OS to window

  • Mac Mini does not recognize external hard drive

    Hello! I have a weird question on my Mac Mini. I have two Seagate to 8 external drives connected via USB to my Mac Mini (mid-2011 with Maverics). The discs worked well, but suddenly one of them will not be recognized by the Mac Mini. I connected the

  • This playlist cannot be downloaded because it includes other types of media or songs that are not eligible.

    iCloud music library playlists can include music from your music library to iCloud. This playlist cannot be downloaded, because it includes other types of media or songs that are not eligible. What does that mean? I have iTunes game and not really en

  • How can I turn off the fn on my Z500?

    I have been struggling with this for a few hours, but I still have no solution. I want to use the F1 to F12 keys as standard keys, but I can't find a way to do it. I looked in the BIOS but theres nothing useful. Can someone tell me how can I turn off