Isolating threads.

I'm making a GUI application that needs to communicate with another PC in a time critical manner. In order to make the communication work as fast as possible, I created a thread that loops through and receives a packet, and then returns another packet. The computer with which it's communication needs to run at a constant rate, so these packets need to get returned ASAP. Anyway, the new thread I created for communication has been assigned MAX_PRIORITY. My understanding is that the lower priority threads would run while this communication thread is waiting to receive a packet.
The problem is, though, that when I manipulate the GUI in this program, (which is fairly elaborate) the communication routine fails to send its packets through quickly enough. I don't care at all how sluggish the GUI is, though. Why is this happening? I thought that if I gave a thread MAX_PRIORITY, it would always run whenever it is runnable. It runs fast enough when I don't interact with the program, so I know it's the GUI functionality that is creating the problem.
Thanks,
Andy

You are using Java for something that it is not designed for. If you want maximum performance, you should have written it in C++. Java is NOT designed to do time critical tasks.
On that note, Swing is not as fast as you would like it to be (how can it be, it has to render on multiple platforms). So maybe you can split up your program. Create one program that receives the packages, and then another application which has the Swing GUI. Then you need to figure out some way to let the applications communicate with eachother.

Similar Messages

  • Thread count in a distributed service

    Hi,
         i needed some information on the thread-count attribute in a distributed service. i would like to know how do we decide on the thread count. would increasing the thread count in the tangosol-coherence.xml increase the performance of tangosol as well.
         looking forward to your help
         Thanks
         Jigs

    To go into this a bit further...
         Each service instance has its own primary thread. This thread has the option of using its own isolated thread pool if the thread-count is greater than zero. If the thread-count is zero, then all work will be performed by the primary service thread. If the thread-count is greater than zero, then all work will be performed by the thread pool (the primary thread acts as a task coordinator).
         Note that the thread-count is per-service and per-cluster-member. Each cache service has a unique name. The CacheFactory class uses a single cache service instance for each cache type (Replicated/Distributed/etc). If you manually create additional cache services, they will each have their own isolated thread pools.
         Additionally, each Invocation service has its own thread pool. This setting is very important as the Invocation service is quite often used to execute long-running user tasks. If the thread pool is saturated with user tasks, then further calls to the Invocation service will block until user tasks complete and threads become available. Using named Invocation service instances will allow you to isolate critical tasks for better application availability.
         Note that this information is current as of Coherence 2.5, but may change in future releases as threading models have a huge impact on performance and scalability. Having said that, there are no significant changes planned at this point in time.
         Jon Purdy
         Tangosol, Inc.
         =================
         Added 2004-12-02 by JP:
         Also, as a very specific instance, the backup copy(ies) of a distributed cache are created on the service thread ... this means that while backup copies are being created on a node, no new tasks will be dispatched to that service's thread pool. For in-memory backup copies, this is actually optimal as adding an item to a HashMap/HashTable is roughly as fast as handing it off to another thread. However, if the backup-copy is configured to disk-based storage (or other high-latency resource), an asynchronous backup implementation should be used to eliminate latency. See AsyncBinaryStore for more information.

  • Worker Threads: Created by model or by controller?

    Sometimes models needs to access blocking devices, like network cards, databases, files, and so on. This should be done by worker threads or services. But who is in charge of that? The controller or the model itself? I tend to say it is the model, as only the model knows about the fact that it accesses a blocking object. On the other hand, it is said that a model should be a POJO, so it would be the controller's job.
    Is there a best practice or general design rule?

    It's impossible to make a general recommendations, but I'd say in many cases the answer to this question is really that the worker threads are created by neither a model or controller.  Threads often need to be associated with processes and tasks which is independent of models and controllers.  Instead you can use dependency injection to inject references into controllers to a common object instances which control isolated threading logic and implementation and encapsulate it to server a given responsibility (such as blocking server communication), with the entity providing this functionality also providing event driven callbacks to the models and controllers, so that they can get notified of changes for tasks spawned based upon their requests.  For example, if you look at the Java JEE model, entity classes and controllers in that model usually never explicitly create or reference threads (that portion of JEE really a pretty general programming mechanism and is also applicable to client code in JavaFX).
    MVC isn't a panacea solution to everything.  In fact it tends to be overly quoted and widely misunderstood and what it actually is is open to different interpretation by different readers.  There is a great discussion of MVC by Martin Fowler.  Everybody claims to do MVC, and they are all doing it, they are just doing it in a different way, which is fine, but it means that it is not a very good reference in trying to communicate solutions to issues such as architecting a multi-threaded application.
    What I would recommend instead of analyzing your entire application from an MVC viewpoint, is to use CRC modeling on it (class/responsibilities/collaborations), you can google it to see how it works if you don't already know.  That way you are thinking about how to architect and build a solution to your application domain issues rather than trying to shoehorn solutions into a certain framework.  Sure MVC is a great thing and is appropriate for many things, just make sure you really want to think from that viewpoint for a particular piece of the solution you are building.
    With threading, you generally want to write as little concurrent code as possible.  You also want this code compartmentalized, so you only need to study the concurrent code in one place (hopefully a single class or at most a single package).  You also don't want the knowledge and use of the threads to leak.  For example, ensure that almost all the code you write is only accessing a single thread so that you don't have to worry about concurrency related bugs and reasoning about concurrency in most of your code.  This is the way the JavaFX system works.  It has multiple threads internally for application processing and rendering, but from a user point of view, all the user application code just runs on a single JavaFX application thread.  This makes the user code less error prone and easier to reason about and also simplifies the library API and usage greatly.
    So let's say you have a server communication API which makes use of a multithreaded client pool of server connections such as apache HTTP components.  Create a single class, e.g. Communicator with methods ResponseMessage send(Location destination, RequestMessage requestMessage) and void sendAsync(Location destination, RequestMessage requestMessage, Callback<ResponseMessage,Void> callback).  The async version, can make use of Platform.runLater, to ensure your callback is invoked on the JavaFX application thread - then your calling JavaFX application code never needs to worry about the internal threading implementation of the communicator, it just reacts to an event driven callback (the same way something like the snapshot API works).  If you need more fine grained feedback and control over the async task from your application, than rather than having a simple callback, you can return a Worker/Task which can be monitored for progress within your JavaFX application, see for instance the LoadWorker in WebEngine.  If your communication implementation is actually reasonably involved and can't be implemented in a single class, that is OK, just make Communicator a facade and use multiple classes in the internal communicator package implementation, but don't use any of that implementation outside of the communicator package.  You can use a dependency injection framework such as afterburner to inject a reference to a communicator into your FXML controllers.

  • Best practices for installing Win 10 under Hyper-V on Server 2012R2 host

    Yeah, yeah, I know I could probably get my answers after spending 10 hours reading hundreds of isolated threads here.  I've already put in about 2 hours, and I'm exhausted.  Plus, this site does not have a very sophisticated search function.
    I want to install Win10 as a VM on my Server 2012R2 machine.  I am not currently hosting any other VMs, so my first decision was whether to try it using Hyper-V or VirtualBox.  I started with VirtualBox, but I ran into two problems: networking
    and video.  Also, VirtualBox itself seems to have some issues with failing to install the extension pack.  So now I think I'll give Hyper-V a shot.
    I found some blog posts from last year providing guidance on setting up Hyper-V for Win10, but given the rate of change of this beta OS, I expect there are many new "features" that can be mitigated against by specific settings on the VM.
    Some specific questions:
    1. Generation 1 or Generation 2 in the Hyper-V setup?  The blogs I've seen say to use Gen1, but provide no justification.  Perhaps because they are using Win8 as the host?  I am using 2012R2.
    2. Does the Win10 ISO file need to be continually available to the VM, or is it only used in the initial installation?
    3. How do I get the VM to access the GPU card, which has lots of memory, over the useless onboard video chip which only has 8MB and no 3D instruction set?  This was a dealbreaker with VirtualBox.
    4. I anticipate many issues with networking, but I'll start with this: I have dual onboard NICs going into a managed switch.  Should I just give one physical NIC to the VM and let the host have the other?  I think I'm going to have some issues
    with DHCP IP address assignment, but we'll see.  Any best practices here would be helpful.
    Thanks.

    >1.
    I'd use Gen 1, that is a BIOS type boot, but that's just because I've had
    less trouble than with Gen2 VM's.
    >2.
    Only during install, refresh, reset, or sfc.
    >3.
    No virtualization solution does it easily, but there is RemoteFX if you can
    get a Windows 10 client to use it.  I've never tried.
    http://social.technet.microsoft.com/wiki/contents/articles/16652.remotefx-vgpu-setup-and-configuration-guide-for-windows-server-2012.aspx
    >4.
    That's what I would do (assigning one NIC to the VM, and one the host).  If
    both are receiving an IP address right now from DHCP, they will continue to
    do so the new way unless you have a managed switch that would prevent more
    IP addresses.  It's hard to tell...
    Bob Comer

  • Airport Express REALLY stopped working

    My Airport Express has really stopped working: dead as a dodo, defunct, etc. It doesn't show in Airport Admin Utility or in iTunes, and the front light is also dead. I have tried changing the easy-access fuse but it makes no difference.
    I assume it has rather annoyingly just died, but why or how I do not know. Is there anything else I can try or do? Is it worth having it repaired, given the relatively low cost?

    Apple has already killed the main thread about this topic months ago, and have left isolated thread to develop a bit before sometimes deleting them: http://www.hardmac.com/news/2006-08-25/#5851
    anyway, our curretn investigations show that APX with serial starting with HS4xx or HS5xx or even HS6xx are mostly affected by the sudden death syndroma.
    other APX series manufacture with a serial starting with 6F are much much less prone to die after the end of the warranty.
    Please record your defective APX via the following link:
    http://www.macbidouille.com/apxdefect.php
    and visit hardmac forum to follow the story: http://forum.hardmac.com

  • Safari stalls during Time Machine backups

    Ever since I upgraded to the combination of OS X 10.6.8 and Safari 5.1 (my workflow is not yet Lion-ready), I've been seeing Safari stall while Time Machine is running its automatic backup. I get the spinner on trying to interact with any tab's content, and then Safari tells me web pages are unresponsive and must all be reloaded (which itself baffles me...why do *all* my 100+ tabs have to be reloaded in this case? Aren't they each an isolated thread now?). This continues throughout the backup. Once the backup is finished, I can tell Safari to reload a tab and everything's fine again.
    Other apps will also sometimes become unresponsive during backups, but none as predictably as Safari. Some sites are more likely to start the stall cascade than others (Facebook is the worst culprit, though that may be due to my use of the Better Facebook extension). It's bad enough that I've tweaked the Time Machine settings to back up only every four hours instead of every hour, just so I can get a decent period of time between backups where I can work. (If I let it backup every hour, one backup is barely complete before the next one starts, leaving Time Machine essentially constantly backing up.)
    (Based on what advice has come up when I've googled this question, I will point out that Time Machine itself is not freezing. The backups themselves are proceeding normally, though perhaps more slowly than I'd prefer. It's only other apps I'm trying to use while TIme Machine is performing a backup that are freezing.)
    I've taken to watching CPU percentage during backups, through iStat Menus, and it never spikes at these times, so it doesn't seem that processor capacity is an issue. The only other thing that comes to mind as a possible cause is disk access speed—could my internal hard drive simply not be fast enough to keep up with both an active backup and the large number of tabs open in Safari at the same time? If so, is there a fix that doesn't involve replacing my internal hard drive?

    OK. Problem solved.  Did a total clean install of Lion and stopped using Time Machine altogether.  Using Memeo Life Agent backup app on both Macs and sending backups to a 1 ter network drive. 
    Found restoring via Time Machine to be unreliable.  Also relized that with Lion and most other apps avilable for clean install via the net, I don't really need to backup my whole system as Time Machine provides. 
    Both Macs now run really well and no more problems.
    Note: When using Memeo with a network dirve make sure to make that drive automatically mounted on startup. You can do this in System Preferences/Users/Login Items.
    Done!

  • Follow up on an old thread about memory utilization

    This thread was active a few months ago, unfortunately its taken me until now
    for me to have enough spare time to craft a response.
    From: SMTP%"[email protected]" 3-SEP-1996 16:52:00.72
    To: [email protected]
    CC:
    Subj: Re: memory utilization
    As a general rule, I would agree that memory utilzation problems tend to be
    developer-induced. I believe that is generally true for most development
    environments. However, this developer was having a little trouble finding
    out how NOT to induce them. After scouring the documentation for any
    references to object destructors, or clearing memory, or garbage collection,
    or freeing objects, or anything else we could think of, all we found was how
    to clear the rows from an Array object. We did find some reference to
    setting the object to NIL, but no indication that this was necessary for the
    memory to be freed.
    I believe the documentation, and probably some Tech-Notes, address the issue of
    freeing memory.
    Automatic memory management frees a memory object when no references to the
    memory
    object exist. Since references are the reason that a memory object lives,
    removing
    the references is the only way that memory objects can be freed. This is why the
    manuals and Tech-Notes talk about setting references to NIL (I.E. freeing memory
    in an automatic system is done by NILing references and not by calling freeing
    routines.) This is not an absolute requirement (as you have probably noticed
    that
    most things are freed even without setting references to NIL) but it accelerates
    the freeing of 'dead' objects and reduces the memory utilization because it
    tends
    to carry around less 'dead' objects.
    It is my understanding that in this environment, the development tool
    (Forte') claims to handle memory utilization and garbage collection for you.
    If that is the case, then it is my opinion that it shoud be nearly
    impossible for the developer to create memory-leakage problems without going
    outside the tool and allocating the memory directly. If that is not the
    case, then we should have destructor methods available to us so that we can
    handle them correctly. I know when I am finished with an object, and I
    would have no problem calling a "destroy" or "cleanup" method. In fact, I
    would prefer that to just wondering if Forte' will take care of it for me.
    It is actually quite easy to create memory leaks. Here are some examples:
    Have a heap attribute in a service object. Keep inserting things into
    the heap and never take them out (I.E. forgot to take them out). Since
    service objects are always live, everything in the heap is also live.
    Have an exception handler that catches exceptions and doesn't do
    anything
    with the error manager stack (I.E. it doesn't call task.ErrMgr.Clear).
    If the handler is activated repeatedly in the same task, the stack of
    exceptions will grow until you run out of memory or the task terminates
    (task termination empties the error manager stack.)
    It seems to me that this is a weakness in the tool that should be addressed.
    Does anyone else have any opinions on this subject?
    Actually, the implementation of the advanced features supported by the Forte
    product
    results in some complications in areas that can be hard to explain. Memory
    management
    happens to be one of the areas most effected. A precise explanation to a
    non-deterministic process is not possible, but the following attempts to
    explain the
    source of the non-determinism.
    o The ability to call from compiled C++ to interpreted TOOL and back
    to compiled C++.
    This single ability causes most of the strange effects mentioned in
    this thread.
    For C++ code the location of all variables local to a method is not
    know
    (I.E. C++ compilers can't tell you at run-time what is a variable
    and what
    isn't.) We use the pessimistic assumption that anything that looks
    like a
    reference to a memory object is a reference to a memory object. For
    interpreted
    TOOL code the interpreter has exact knowledge of what is a reference
    and what
    isn't. But the TOOL interpreter is itself a C++ method. This means
    that any
    any memory objects referenced by the interpreter during the
    execution of TOOL
    code could be stored in local variables in the interpreter. The TOOL
    interpreter
    runs until the TOOL code returns or the TOOL code calls into C++.
    This means
    that many levels of nested TOOL code can be the source of values
    assigned to
    local variables in the TOOL interpreter.
    This is the complicated reason that answers the question: Why doesn't a
    variable that is created and only used in a TOOL method that has
    returned
    get freed? It is likely that the variable is referenced by local
    variables
    in the TOOL interpreter method. This is also why setting the
    variable to NIL
    before returning doesn't seem to help. If the variable in question is a
    Array than invoke Clear() on the Array seems to help, because even
    though the
    Array is still live the objects referenced by the Array have less
    references.
    The other common occurrence of this effect is in a TextData that
    contains a
    large string. In this case, invoking SetAllocatedSize(0) can be used
    to NIL
    the reference to the memory object that actually holds the sequence of
    characters. Compositions of Arrays and TextData's (I.E. a Array of
    TextData's
    that all have large TextDatas.) can lead to even more problems.
    When the TOOL code is turned into a compiled partition this effect
    is not
    noticed because the TOOL interpreter doesn't come into play and
    things execute
    the way most people expect. This is one area that we try to improve
    upon, but it is complicated by the 15 different platforms, and thus
    C++ compilers,
    that we support. Changes that work on some machines behave
    differently on other
    machines. At this point in time, it occasionally still requires that
    a TOOL
    programmer actively address problems. Obviously we try to reduce
    this need over
    time.
    o Automatic memory management for C++ with support for multi-processor
    threads.
    Supporting automatic memory management for C++ is something that is
    not a very
    common feature. It requires a coding standard that defines what is
    acceptable and
    what isn't. Additionally, supporting multi-processor threads adds
    its own set of
    complications. Luckily TOOL users are insulated from this because
    the TOOL to C++
    code generator knows the coding standard. In the end you are
    impacted by the C++
    compiler and possibly the differences that occur between different
    compilers and/or
    different processors (I.E. Intel X86 versus Alpha.) We have seen
    applications that
    had memory utilization differences of up to 2:1.
    There are two primary sources of differences.
    The first source is how compilers deal with dead assignments. The
    typical TOOL
    fragment that is being memory manager friendly might perform the
    following:
    temp : SomeObject = new;
    ... // Use someObject
    temp = NIL;
    return;
    When this is translated to C++ it looks very similar in that temp
    will be assigned the
    value NULL. Most compilers are smart enough to notice that 'temp' is
    never used again
    because the method is going to return immediately. So they skip
    setting 'temp' to NULL.
    In this case it should be harmless that the statement was ignored
    (see next example for a different variation.) In more
    complicated examples that involve loops (especially long
    lived event loops) a missed NIL assignment can lead to leaking the
    memory object whose
    reference didn't get set to NIL (incidentally this is the type of
    problem that causes
    the TOOL interpreter to leak references.)
    The second source is a complicated interaction caused by history of
    method invocations.
    Consider the following:
    Method A() invokes method B() which invokes method C().
    Method C() allocates a temporary TextData, invokes
    SetAllocatedSize(1000000)
    does some more work and then returns.
    Method B() returns.
    Method A() now invokes method D().
    Method D() allocates something that cause the memory manager to look
    for memory objects to free.
    Now, even though we have returned out of method C() we have starting
    invoking
    methods. This causes us to use re-use portions of the C++ stack used to
    maintain the history of method invocation and space for local variables.
    There is some probability that the reference to the 'temporary' TextData
    will now be visible to the memory manager because it was not overwritten
    by the invocation of D() or anything invoked by method D().
    This example answers questions of the form: Why does setting a local
    variable to
    NIL and returning and then invoking task.Part.Os.RecoverMemory not
    cause the
    object referenced by the local variable to be freed?
    In most cases these effects cause memory utilization to be slightly
    higher
    than expected (in well behaved cases it's less than 5%.) This is a small
    price to pay for the advantages of automatic memory management.
    An object-oriented programming style supported by automatic memory
    management makes it
    easy to extended existing objects or sets of objects by composition.
    For example:
    Method A() calls method B() to get the next record from the
    database. Method B()
    is used because we always get records, objects, of a certain
    type from
    method B() so that we can reuse code.
    Method A() enters each row into a hash table so that it can
    implement a cache
    of the last N records seen.
    Method A() returns the record to its caller.
    With manual memory management there would have to be some interface
    that allows
    Method A() and/or the caller of A() to free the record. This
    requires
    that the programmer have a lot more knowledge about the
    various projects
    and classes that make up the application. If freeing doesn'
    happen you
    have a memory leak, if you free something while its still
    being used the
    results are unpredictable and most often fatal.
    With automatic memory management, method A() can 'free' its
    reference by removing
    the reference from the hash table. The caller can 'free' its
    reference by
    either setting the reference to NIL or getting another
    record and referring
    to the new record instead of the old record.
    Unfortunately, this convenience and power doesn't come for free. Consider
    the following,
    which comes from the Forte' run-time system:
    A Window-class object is a very complex beast. It is composed of two
    primary parts:
    the UserWindow object which contains the variables declared by the
    user, and the
    Window object which contains the object representation of the window
    created in
    the window workshop. The UserWindow and the Window reference each
    other. The Window
    references the Menu and each Widget placed on the Window directly. A
    compound Window
    object, like a Panel, can also have objects place in itself. These
    are typically
    called the children. Each of the children also has to know the
    identity of it's
    Mom so they refer to there parent object. It should be reasonably
    obvious that
    starting from any object that make up the window any other object
    can be found.
    This means that if the memory manager finds a reference to any
    object in the Window
    it can also find all other objects in the window. Now if a reference
    to any object
    in the Window can be found on the program stack, all objects in the
    window can
    also be found. Since there are so many objects and the work involved
    in displaying
    a window can be very complicated (I.E. the automatic geometry
    management that
    layouts the window when it is first opened or resized.) there are
    potentially many
    different reference that would cause the same problem. This leads to
    a higher than
    normal probability that a reference exists that can cause the whole
    set of Window
    objects to not be freed.
    We solved this problem in the following fashion:
    Added a new Method called RecycleMemory() on UserWindow.
    Documented that when a window is not going to be used again
    that it is
    preferably that RecycleMemory() is invoked instead
    of Close().
    The RecycleMemory() method basically sets all references
    from parent to
    child to NIL and sets all references from child to
    parent to NIL.
    Thus all objects are isolated from other objects
    that make up
    the window.
    Changed a few methods on UserWindow, like Open(), to check
    if the caller
    is trying to open a recycled window and throw an
    exception.
    This was feasible because the code to traverse the parent/child
    relationship
    ready existed and was being used at close time to perform other
    bookkeeping
    operations on each of the Widgets.
    To summarize:
    Automatic memory management is less error prone and more productive but
    doesn't come totally for free.
    There are things that the programmer can do that assists the memory
    manager:
    o Set object reference to NIL when known to be correct (this
    is the
    way the memory is deallocated in an automatic system.)
    o Use methods like Clear() on Array and SetAllocatedSize()
    on TextData to
    that allow these objects to set their internal
    references to NIL
    when known to be correct.
    o Use the RecycleMemory() method on windows, especially very
    complicated
    windows.
    o Build similar type of methods into your own objects when
    needed.
    o If you build highly connected structures that are very
    large in the
    number of object involved think that how it might be
    broken
    apart gracefully (it defeats some of the purpose of
    automatic
    management to go to great lengths to deal with the
    problem.)
    o Since program stacks are the source of the 'noise'
    references, try
    and do things with less tasks (this was one of the
    reasons that
    we implemented event handlers so that a single task
    can control
    many different windows.)
    Even after doing all this its easy to still have a problem.
    Internally we have
    access to special tools that can help point at the problem so that
    it can be
    solved. We are attempting to give users UNSUPPORTED access to these
    tools for
    Release 3. This should allow users to more easily diagnose problems.
    It also
    tends to enlighten one about how things are structured and/or point out
    inconsistencies that are the source of known/unknown bugs.
    Derek
    Derek Frankforth [email protected]
    Forte Software Inc. [email protected]
    1800 Harrison St. +510.869.3407
    Oakland CA, 94612

    I beleive he means to reformat it like a floppy disk.
    Go into My Computer, Locate the drive letter associated with your iPod(normally says iPod in it, and shows under removable storage).
    Right click on it and choose format - make sure to not have the "quick format" option checked. Then let it format.
    If that doesnt work, There are steps somewhere in the 5th gen forum( dont have the link off hand) to try to use the usbstor.sys to update the USB drivers for the Nano/5th gen.

  • Image repaint preformance and threading

    Folks,
    I'm trying to make this sucker run faster.
    My question is, can anyone please guide me, especially with regards synchronising the Threads more efficiently... I'm thinking of using join and i]notify to make the "navigator" threads yield to the swing threads, to give it a chance to repaint before continuing... does this sound sane to you?
    Currently, without the thread.sleep it paints get the first "burst", and then nothing until the alrorithm has completed... exactly not what I wanted, because the whole point of this GUI is to watch the algorithm at work... sort of a "visual debugger"... I find that watching an algorithm play out helps me to "imagineer" ways of improving it... and in this case improvement means optimisation... it's all about getting from A-J faster than anyone else on the planet, especially those smarty-wishbone-legs C# programmers ;-)
    The code is too big to post (darn that 7500 char limit!) so I'll split it over several posts here, and I've also posted it as a single download to [MazeOfBoltonGUI2.java|http://groups.google.com/group/comp_lang_java_exchange/web/MazeOfBoltonGUI2.java] on my google group (comp lang java exchange).
    Cheers all. Keith.
    package forums.maze;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.SortedMap;
    import java.util.TreeMap;
    import java.util.Stack;
    import java.util.Queue;
    import java.util.PriorityQueue;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.concurrent.Callable;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.Future;
    import java.util.concurrent.ExecutionException;
    import java.awt.Dimension;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Font;
    import java.awt.image.BufferedImage;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.SwingWorker;
    import java.io.PrintWriter;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    * A Visual debugger,
    * for the [A* Alogorithm|http://en.wikipedia.org/wiki/A*_search_algorithm] navigator
    * of the [Maze Of Bolton|http://cplus.about.com/od/programmingchallenges/a/challenge12.htm]
    * as implemented by [Prometheuz|http://forums.sun.com/profile.jspa?userID=550123]
    * with GUI by [Kajbj|http://forums.sun.com/profile.jspa?userID=91610]
    * hacked together by [Keith Corlett|http://forums.sun.com/profile.jspa?userID=640846]
    * and posted on [Sun's Java Forum|http://forums.sun.com/thread.jspa?threadID=5319334]
    * and posted on [Google news group|http://groups.google.com.au/group/comp_lang_java_exchange/]
    public class MazeOfBoltonGUI2
      static final char[][] matrix = readMatrix("map.txt");
      public static void main(String[] args) {
        SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              try {
                MazeNavigator navigator = new MazeNavigator(matrix);
                JFrame frame = new JFrame("MazeOfBoltonGUI2");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setContentPane(new MainPanel(navigator));
                frame.pack();
                frame.setVisible(true);
              } catch (Exception e) {
                e.printStackTrace();
       * Reads the file into a char matrix[rows,cols] ie: an array of char arrays.
       * @param String filename - the name of the file to read
       * @return a fixed length array of strings containing file contents.
      private static char[][] readMatrix(String filename) {
        try {
          BufferedReader input = null;
          try {
            input = new BufferedReader(new FileReader(filename));
            char[][] matrix = null;
            List<String> lines = new ArrayList<String>();
            String line = null;
            while ( (line = input.readLine()) != null ) {
              lines.add(line);
            int rows = lines.size();
            matrix = new char[rows][];
            for (int i=0; i<rows; i++) {
              matrix[i] = lines.get(i).toCharArray();
            System.err.println("DEBUG: rows="+rows+", cols="+matrix[0].length);
            return matrix;
          } finally {
            if(input!=null)input.close();
        } catch (IOException e) {
          e.printStackTrace();
          throw new IllegalStateException("Failed to readMatrix!", e);
    class MainPanel extends JPanel
      private static final long serialVersionUID = 1L;
      // button panel
      private final JButton goButton;
      // maze panel
      private final MazeNavigator navigator;
      private final Monitor<Path> monitor;
      private BufferedImage background;
      private BufferedImage image;
      private List<Path>currentPaths;
      public MainPanel(MazeNavigator navigator) {
        this.navigator = navigator;
        this.monitor = new SwingMonitor();
        this.goButton = new JButton("Go");
        goButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              final String caption = goButton.getText();
              goButton.setVisible(false);
              monitor.execute();
        add(goButton);
        setPreferredSize(new Dimension(navigator.maze.cols*3, navigator.maze.rows*3)); //w,h
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (image==null) {
          image = (BufferedImage)createImage(navigator.maze.cols, navigator.maze.rows);
          mazeColors = createMazeColors(navigator.maze);
        this.draw(image.createGraphics());
        ((Graphics2D)g).drawImage(image, 0, 0, super.getWidth(), super.getHeight(), null);
      private static Color[][] mazeColors;
      private static Color[][] createMazeColors(Maze maze) {
        Color[][] colors = new Color[maze.rows][maze.cols];
        for (int r=0; r<maze.rows; r++) {
          for (int c=0; c<maze.cols; c++) {
            colors[r][c] = getColor(maze.matrix[r][c].ch);
        return colors;
      }*... PTO ...*

    I'm persuaded that the main issue (no intermediate results drawn) is the improper use of SwingWorker.
    When you've got over it, you may want to consider other smaller-effect optimizations:
    Reconsider usage of an offscreen image*
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (image==null) {
          image = (BufferedImage)createImage(navigator.maze.cols, navigator.maze.rows);
          mazeColors = createMazeColors(navigator.maze);
        this.draw(image.createGraphics());
        ((Graphics2D)g).drawImage(image, 0, 0, super.getWidth(), super.getHeight(), null);
      }At first I didn't get why you wanted to draw an offscreen image, then paint it to the screen, all that in the EDT.
    After reading the draw() method more closely, I guess you want to ease the coding of the scaling: you draw an image where one cell = one pixel, then paint the image, scaled to the panel's display size.
    In terms of performance, I don't know how it stands:
    On one hand, the image creation if lighter (1 pixel per cell). And you have a point that the built-in scaling offered by Graphics2D.drawImage(image, size) may be efficient. I can't comment on that, I hope the granphics and hardware acceleration folks will pop in the thread.
    On the other hand, if the built-in scaling had poor performance, it may be good to try what "manual" scaling would bring you. That means, in a simplified version, skip the offscreen image creation, and draw directly on the paintComponent()'s Graphics2D argument. the drawing of a cell at coordinates c,r, for example, would look like:
    g.fillRect(c*CELL_WIDTH, r*CELL_HEIGHT, WIDTH, HEIGHT);Performance apart, the scaling as you do it currently has functional drawbacks, if you want pathes as 1-pixel width lines over large cells:
    - if the maze is smaller (in rows, columns) than the panel displaying it (in pixels), the cells will be scaled but the pathes too: so your 1-pixel lines appear as large as the cells. May or may not be a desired effect.
    - if the maze is larger than the display panel, the cells are shrinked, fine, but the so are the path lines, to a point where they may be invisible (probably depending on color blending, I'm a n00b at graphics operations).
    But maybe I misunderstood the need, and maybe the intended drawing of a path is actually the drawing of the rectangles of all its traversed cells, in special path colors?
    Reconsider intermediate allocations*
    Each paintComponent() call results in the allocation of a 2D-array of Color objects (method createMazeColors(Maze)).
    I don't see what the mazeColors array brings you. I assume you wanted to decouple the determination of colors (depending on cell state) and the rendering of the colors: what does it bring: no performance advantage (on the contrary, it adds a 2D array allocation, and 2xN^2 2D-array access), and does not improve the code readability either (subjective rant, sorry).
    Why don't you pass the Maze as an argument to the draw() method, and call the getColor(cell.ch) from there?
    Side note, maybe a bit subjective: performance apart, the design of the usage of this mazeColor array is a no-go!
    An instance method alters a static variable reference,which is used subsequently in another instance method, with no synchronization. The current code does that in a single thread (+paintxxx()+ is only called in the EDT), which keeps that safe (I'd dare to say: by luck), but considerations exposed below may have you refactor the design to introduce other threads, and may exhibit the thread-unsafety of this design.
    Consider drawing the image in a background thread.*
    Indeed the technique of drawing to an offscreen image is quite common, but it is often done to improve responsiveness (not raw performance) of Swing applications. Here is a resource about this (what the author calls the passive approach), although it doesn't use a background thread.
    The idea is that if a paintCompobnent() methods involves lots of computation (arithmetics of traversing a 2D model, scaling things, etc.), this takes CPU times in the EDT, and all subsequent events (such as, a MouseEvent, but also other painting events) keep pending on the event queue, which is consumed by the single event-dispatch thread. The result is that the UI appear unresponsive, and painting of other areas may seem hung.
    The idea is to move the computation to a background thread, which posts rendering to the EDT when the Image is ready to be displayed.
    Of course this doesn't gain any CPU time. This only ensures the EDT uses a minimal part of this CPU (only render and image and process events), instead of performing the whole computation.
    In your case you already have a background thread, and indeed an appropriate choice, a SwingWorker. The application of this technique would consist in calling the draw() method in the worker thread (in the update(Path) method), and invoke super.publish() only after the image has been updated. Note that the process(List<Path>) could then ignore its argument (you may reconsider the choice of type parameter of the worker), and simply get the latest version of the image attribute).
    Of course in this technique, the offscreen image filling is called synchronously from the Navigator, so this halts the algorithm part itself, for the duration of the image generation. You may refine the technique by spawning a dedicated thread for the image generation - with subtle guard code to handle occasions when the algorithm goes faster than the image generation, and posts a new update(Path) while the image generation for the previous path has not completed yet...
    Recuce the number of things to redraw*
    Two parts:
    first, depending on the number of cells and pathes, there may be (yet another) optimization, to not redraw the whole offscreen image, but only the cells/path that have changed in the last update(). In particular, if a path is not a line but a list of cells, then it's quite easy, reusing the current offscreen image, to only fillRect(...) the appropriate cells.
    Second, if a path is not rendered as a thin line over larger cells, but as cells themselves rendered in special path colors, you may paint cells and path in one go: instead of drawing, first the cells, then the path, draw only the cells, electing the color using a decision method such as:
    private Color getColor(Cell) {
        if (cell.getPathState()!=NOT_IN_ANY_PATH) {
            return getColor(cell.getPathState());
        else {
            return getColor(cell.ch);
    }Of course this forces you to modify your data model, and update the new pathState as part of the algorithm (or better isolated, in the update(Path) method, before invoking the drawing machinery). Maybe that was the intention of the mazeColors array?
    I haven't studied your other posts on the logic of the MazeOfBolton algorithm, so I don't know if it's acceptable for you that a cell appear to have only one path state, as opposed to one for each of the pathes that traverse it. This last trick may then seem incorrect, but please consider it as only a graphical information, and indeed your current image drawing draws only ONE path for a given cell (the last path in currentPaths that traverses this cell ).

  • A big cup of "zip it" or the definative final P67 vs X58 answer thread

    none of this will matter in 6 months however until then... this should be a sticky
    2600K, Motherboard, 16gig ram $711
    990x, motherboard, 12 gig ram $1408  24Gig ram $1552
    why the 990x? its the only processor that can match or beat the 2600k either stock for stock or 4.7 vs 4.0GHz over clocks
    this is fact not fiction you can not go by PPBM user submitted, due to far too many varibles both in user set up and hardware differences.
    however when we use PPBM with identical systems other than swapping the 990 to the 2600 it shows the same as our in house tests.
    (and not a negative comment with concern to the wonderful makers of PPBM Bill and Harm so please dont tkae it that way.. for an end user submitted test its fabulous!)
    Adobe CS5.5:
    4 WD 1Tb Sata 64 Meg Cache 600 Drives in 2 Raid 0 arrays
    Video material - AVCHD 1080P 24 Frame Each Cut to 30 minutes of material
    Export Codec - H264 HDTV 1080P 24 Preset Default
    4 Effects per Layer - Fast Color Corrector, Brightness & Contrast, Video Limiter, Sharpen
    Each Layer Scaled to 50% for 4 frame PinP view.
    I7 990X 4.0 GHz
    24GB Blackline 1600 CL 9  <--- this puts the test with 24gig to bed
    580GTX <---- has better video as well hmmm.
    3 Layer - 32:06
    4 Layer - 34:45
    >>>>>>>>>>>>>>>>>>>>>>>>
    I7 2600K 4.7 GHz   <----winner with only 16 gig ram how is this possible? and if a 990 cant beat it how can a 920?
    16GB Blackline 1600 CL 9
    570GTX
    3 Layer - 30:46
    4 Layer - 33:36
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    you need a big raid array for AVCHD!
    Complete nonsense.. same applies for needing a dual Xeon..
    same test with a big 8 drive raid array
    I7 2600K 4.7 GHz
    16GB Blackline 1600 CL 9
    570GTX
    8 WD 1Tb Sata 64 Meg Cache 600 Drives in Raid 5 array with RS2BL080 controller
    3 Layer - 29:33
    4 Layer - 33:26  WOW that finished so much faster..  NOT.
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
    but you can't add a Capture/preview card to P67!
    really? where did you hear this absurd fallacy? do you believe everything you read on the internet?
    we have shipped a huge amount of systems with Decklink, in them, a few Aja and a few matrox <-- driver issue not P67 issue.. same issue occurs on X58
    We are not talking about using all the slots only adding a 1X card
    16x is off the processor and isolated (assuming you only have a vid card) however there are generally 2 16x when adding something into the 2nd 16x is when that get reduced to 2x 8 electrical
    (Will have a definitive answer as to if adding a raid card into the other 16x will reduce video or drive ability in a day or so) tired of hearing about that as well..
    There is an additional 8 PCIe X1 off the south bridge if you will or PCH. An average board  looks like this.
    1) firewire
    2) GB Ethernet
    3) eSata
    4) PCIe to PCI bridge
    5) PCIe to USB3
    6,7,8) actual 1x slots
    Each 1x is capable of 5GB/s
    The DMI is 20GB/s
    That means 4 of the 1X can be active at full bandwidth at once, (where it seems people arrived at the 20 lanes) or all 8 at 1/2 bandwidth.
    Let me also remind you that I know of nothing that saturates the PCIe bus 100% not even raid cards (assuming an 8x or 4x slot) and certainly not a capture card.
    In various benchmark tests of PCI vs PCIe there were little to no difference in ability. (raid cards, capture cards, pro audio interfaces)
    All that to say again nothing uses the full bandwidth.
    Looking at all 8 PCIe 1x slots/connections I don’t see 4 being used simultaneously under any circumstance. Even adding a pro audio interface into the mix.
    So again adding a capture/preview card to the sandy bridge platform works 100% right and with 100% performance ability. (not counting the driver issues with matrox)
    But you can't add a raid card to P67!
    really?
    i am here to tell you yes you can and without using N200 chipset motherboard.
    we (well Slacker Eric, in his defense he has been swamped) finally tested this. i only asked since Jan/Feb.
    Adding an Intel RSBL080 8 drive raid controller see above test. not only did performance NOT decrease it increased, albeit a whopping 10 seconds.
    yes the video card was reduced to a paltry 8x and according to the bios only running @ 2.5 GB/s where the raid card showed a full 5GB/s
    yet there was no drop in cuda perfomance at all and all effects we use on our tests are cuda effects.
    Now in all fairless of disclosure the drive benchmarks dropped from our previous tests on X58 which is odd, we are guessing the video card as its ramping up would take bandwidth from the controller even though its supposed to be running 8x.
    previous X58
    Intel SAS RS2PI080 8 Port controller with 512 DDR2 Ram
    8x WD 1TB SATA 6 Gb/s, 64 MB Cache, 7200 RPM
    8 Drive Raid 5 - 703.8MB/s read 670MB/s Write
    with Sandy Bridge  550MB/s read  522 MB/s write
    so here we do see a decent drop in performance.
    1) this is still plenty of speed for even RED footage.
    2) if you need more speed than that you should be on dual 3.33GHz Xeons anyway
    3) the only point to having a large raid on a sandy or X58 in the first place is for redundacy. and even that does not replace back up..
    So i can not see nor justify any reason to continue buying an X58 platform unless you just like to spend $841 more for nothing!
    and remember these are the "budget" Sandy Bridge
    i can't wait  until they release the big dogs.
    Scott
    ADK

    Colin,
    I don't consider your system "old" (i7-930, X58, 24GB RAM, GTX 480, Samsung F3 1TB RAID), and it certainly sounds like a system that you could add to if you want to eeech out a bit more performance without any concerns of throwing money away. Heck, it sounds a lot like my current build, which is only 3 months old!
    If I had to guess, your best bang-for-the-buck improvement for your system would be to add a 2x1TB RAID 0 that you can use for previews, media cache, and exports; see Harm's Generic Guideline for Disk Setup thread for configuration details. If you try that and still want more ooomph, then go for the i7-970 too.
    Regarding the request for PPBM5 results, I find those very helpful to use as a metric to determine if a system has any weak spots. Then after you remedy those weak areas the end result is exactly what you do say that you want -- "real world results"!
    Cheers,
    Jim

  • Can multiple threads write to the database?

    I am a little confused from the statement in the documentation: "Berkeley DB Data Store does not support locking, and hence does not guarantee correct behavior if more than one thread of control is updating the database at a time."
    1. Can multiple threads write to the "Simple Data Store"?
    2. Considering the sample code below which writes to the DB using 5 threads - is there a possibility of data loss?
    3. If the code will cause data loss, will adding DB_INIT_LOCK and/or DB_INIT_TXN in DBENV->open make any difference?
    #include "stdafx.h"
    #include <stdio.h>
    #include <windows.h>
    #include <db.h>
    static DB *db = NULL;
    static DB_ENV *dbEnv = NULL;
    DWORD WINAPI th_write(LPVOID lpParam)
    DBT key, data;
    char key_buff[32], data_buff[32];
    DWORD i;
    printf("thread(%s) - start\n", lpParam);
    for (i = 0; i < 200; ++i)
    memset(&key, 0, sizeof(key));
    memset(&data, 0, sizeof(data));
    sprintf(key_buff, "K:%s", lpParam);
    sprintf(data_buff, "D:%s:%8d", lpParam, i);
    key.data = key_buff;
    key.size = strlen(key_buff);
    data.data = data_buff;
    data.size = strlen(data_buff);
    db->put(db, NULL, &key, &data, 0);
    Sleep(5);
    printf("thread(%s) - End\n", lpParam);
    return 0;
    int main()
    db_env_create(&dbEnv, 0);
    dbEnv->open(dbEnv, NULL, DB_CREATE | DB_INIT_MPOOL | DB_THREAD, 0);
    db_create(&db, dbEnv, 0);
    db->open(db, NULL, "test.db", NULL, DB_BTREE, DB_CREATE, 0);
    CreateThread(NULL, 0, th_write, "A", 0, 0);
    CreateThread(NULL, 0, th_write, "B", 0, 0);
    CreateThread(NULL, 0, th_write, "B", 0, 0);
    CreateThread(NULL, 0, th_write, "C", 0, 0);
    th_write("C");
    Sleep(2000);
    }

    Here some clarification about BDB Lock and Multi threads behavior
    Question 1. Can multiple threads write to the "Simple Data Store"?
    Answer 1.
    Please Refer to http://docs.oracle.com/cd/E17076_02/html/programmer_reference/intro_products.html
    A Data Store (DS) set up
    (so not using an environment or using one, but without any of the DB_INIT_LOCK, DB_INIT_TXN, DB_INIT_LOG environment regions related flags specified
    each corresponding to the appropriate subsystem, locking, transaction, logging)
    will not guard against data corruption due to accessing the same database page and overwriting the same records, corrupting the internal structure of the database etc.
    (note that in the case of the Btree, Hash and Recno access methods we lock at the database page level, only for the Queue access method we lock at record level)
    So,
    if You want to have multiple threads in the application writing concurrently or in parallel to the same database You need to use locking (and properly handle any potential deadlocks),
    otherwise You risk corrupting the data itself or the database (its internal structure).
    Of course , If You serialize at the application level the access to the database, so that no more one threads writes to the database at a time, there will be no need for locking.
    But obviously this is likely not the behavior You want.
    Hence, You need to use either a CDS (Concurrent Data Store) or TDS (Transactional Data Store) set up.
    See the table comparing the various set ups, here: http://docs.oracle.com/cd/E17076_02/html/programmer_reference/intro_products.html
    Berkeley DB Data Store
    The Berkeley DB Data Store product is an embeddable, high-performance data store. This product supports multiple concurrent threads of control, including multiple processes and multiple threads of control within a process. However, Berkeley DB Data Store does not support locking, and hence does not guarantee correct behavior if more than one thread of control is updating the database at a time. The Berkeley DB Data Store is intended for use in read-only applications or applications which can guarantee no more than one thread of control updates the database at a time.
    Berkeley DB Concurrent Data Store
    The Berkeley DB Concurrent Data Store product adds multiple-reader, single writer capabilities to the Berkeley DB Data Store product. This product provides built-in concurrency and locking feature. Berkeley DB Concurrent Data Store is intended for applications that need support for concurrent updates to a database that is largely used for reading.
    Berkeley DB Transactional Data Store
    The Berkeley DB Transactional Data Store product adds support for transactions and database recovery. Berkeley DB Transactional Data Store is intended for applications that require industrial-strength database services, including excellent performance under high-concurrency workloads of read and write operations, the ability to commit or roll back multiple changes to the database at a single instant, and the guarantee that in the event of a catastrophic system or hardware failure, all committed database changes are preserved.
    So, clearly DS is not a solution for this case, where multiple threads need to write simultaneously to the database.
    CDS (Concurrent Data Store) provides locking features, but only for multiple-reader/single-writer scenarios. You use CDS when you specify the DB_INIT_CDB flag when opening the BDB environment: http://docs.oracle.com/cd/E17076_02/html/api_reference/C/envopen.html#envopen_DB_INIT_CDB
    TDS (Transactional Data Store) provides locking features, adds complete ACID support for transactions and offers recoverability guarantees. You use TDS when you specify the DB_INIT_TXN and DB_INIT_LOG flags when opening the environment. To have locking support, you would need to also specify the DB_INIT_LOCK flag.
    Now, since the requirement is to have multiple writers (multi-threaded writes to the database),
    then TDS would be the way to go (CDS is useful only in single-writer scenarios, when there are no needs for recoverability).
    To Summarize
    The best way to have an understanding of what set up is needed, it is to answer the following questions:
    - What is the data access scenario? Is it multiple writer threads? Will the writers access the database simultaneously?
    - Are recoverability/data durability, atomicity of operations and data isolation important for the application? http://docs.oracle.com/cd/E17076_02/html/programmer_reference/transapp_why.html
    If the answers are yes, then TDS should be used, and the environment should be opened like this:
    dbEnv->open(dbEnv, ENV_HOME, DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_INIT_LOG | DB_RECOVER | DB_THREAD, 0);
    (where ENV_HOME is the filesystem directory where the BDB environment will be created)
    Question 2. Considering the sample code below which writes to the DB using 5 threads - is there a possibility of data loss?
    Answer 2.
    Definitely yes, You can see data loss and/or data corruption.
    You can check the behavior of your testcase in the following way
    1. Run your testcase
    2.After the program exits
    run db_verify to verify the database (db_verify -o test.db).
    You will likely see db_verify complaining, unless the thread scheduler on Windows weirdly starts each thread one after the other,
    IOW no two or ore threads write to the database at the same time -- kind of serializing the writes
    Question 3. If the code will cause data loss, will adding DB_INIT_LOCK and/or DB_INIT_TXN in DBENV->open make any difference?
    Answer 3.
    In Your case the TDS should be used, and the environment should be opened like this:
    dbEnv->open(dbEnv, ENV_HOME, DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_INIT_LOG | DB_RECOVER | DB_THREAD, 0);
    (where ENV_HOME is the filesystem directory where the BDB environment will be created)
    doing this You have proper deadlock handling in place and proper transaction usage
    so
    You are protected against potential data corruption/data loss.
    see http://docs.oracle.com/cd/E17076_02/html/gsg_txn/C/BerkeleyDB-Core-C-Txn.pdf
    Multi-threaded and Multi-process Applications
    DB is designed to support multi-threaded and multi-process applications, but their usage
    means you must pay careful attention to issues of concurrency. Transactions help your
    application's concurrency by providing various levels of isolation for your threads of control. In
    addition, DB provides mechanisms that allow you to detect and respond to deadlocks.
    Isolation means that database modifications made by one transaction will not normally be
    seen by readers from another transaction until the first commits its changes. Different threads
    use different transaction handles, so this mechanism is normally used to provide isolation
    between database operations performed by different threads.
    Note that DB supports different isolation levels. For example, you can configure your
    application to see uncommitted reads, which means that one transaction can see data that
    has been modified but not yet committed by another transaction. Doing this might mean
    your transaction reads data "dirtied" by another transaction, but which subsequently might
    change before that other transaction commits its changes. On the other hand, lowering your
    isolation requirements means that your application can experience improved throughput due
    to reduced lock contention.
    For more information on concurrency, on managing isolation levels, and on deadlock
    detection, see Concurrency (page 32).

  • Can you set isolation levels of message-driven bean transactions?

    The problem: I have 3 different message-driven beans which each get a different type of message, except for a field that is common to all. That field is used as the primary key of an entity object. The message-driven beans configured to use a container managed transaction. Each message-driven bean, in processing the message, first does a lookup by primary key to see if the object associated with the key exists, and if it does not, it requests the entity's home object to create it. After that, they do further processing. The problem is that sometimes all the beans simultaneously get a message, resulting in each bean checking for the entity object at about the same time, and if they fail to find it (because none of them has created it yet), each creates an object, all with the same primary key. This is not caught until the beans start to complete their onMessage method, which I believe results in the container committing the transaction. One of the transactions will be committed successfully, while the other two will fail, get rolled back, and then be retried with the same message. The second time through, the other beans will find the entity object (since it has been created and committed) and they will complete correctly. In the end, they right thing occurs, except that there is a troubling exception or 2 in the log telling about the constraint violation (with the primary key) and the rollback. If it was just me, that would be fine, but our customer does not like to see exceptions in the log; that indicates to him that something is wrong.
    So, I am looking for someway to make sure that the actions of the message-driven beans are serialized. One suggestion from a colleague was to set the isolation level of the transactions being used by the container in processing the message-driven beans' onMessage method. However, the documentation does not mention any way to do this for a message-driven bean. Suggestions?
    Is the use of a UserTransaction a better way to do this? If I acquire a UserTransaction within the onMessage method of a message-driven bean, can I set its isolation level? How would this work? When I get a UserTransaction, does each client get a different transaction, or do they all get the same one?

    (1) The WebLogic JMS "unit-of-order" feature is a heavily adopted feature that was specifically designed to handle similar use cases - see the JMS developer guide for extensive documentation. In your use case, if "key" is used to define UOO, then there's no limit on the number of keys that can be processed concurrently, but messages for any particular key will be processed single-threaded in the order in which they were first submitted.
    Note that if you're using distributed destinations, the UOO feature is still fully supported - but the developer and/or administrator needs to decide whether to configure the destination to use "hash" or "path service" based routing (the JMS UOO edoc outlines the trade-offs).
    (2) Another alternative is to use a single MDB with max-beans-free-pool that processes all three types (as the other poster suggested). I think this assumes all MDBs run on the same JVM.
    (3) Another alternative is to use multiple queues, with a single MDB on each Q. Where some sort of hash algorithm is used to determine which Q is for the key. This approach is a "hand-coded" variant of the approach in (1) with "hash" based routing enabled...
    (4) If all MDBs actually do run in the same JVM, a third alternative is to use code the application to use a common lock to protect each key, eg, something like:
    // assume MyLock is simply a class with a "reference counter"
    // assume some global "staticHM" hash map that is all MDBs can access
    onMessage() {
    MyLock lock = null;
    key= msg.getKey();
    synchronized(staticHM) {
    lock = staticHM.get();
    if (lock = null) {
    lock = new lock();
    staticHM.put(key, new lock());
    lock.incRefCount();
    try {
    synchronized(lock) {
    // only one onMessage will be able to lock a particular key at a time
    do your work;
    } finally {
    synchronized(staticHT) {
    if (lock.defRefCount() == 0) staticHM.remove(lock);
    if (lock = null) staticHM.put(key);
    If multiple threads get a message with the same key, then only one thread at a time will work on the key.
    Hope this helps,
    Tom

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

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

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

  • Java.Lang.nullpointerexception issue only isolated to a repository on the job server

    I am having the
    "Java.Lang.nullpointerexception" error message issue only isolated to a repository on the job server.
    This error message appearing when i try to execute or create a new schedule for a job on mgmt console.
    I have few other repositories in the same server, with those repositories i am not having any issues, in terms of executing a job or creating a new schedule.
    Does any one had the similar issue, and know how to resolve it.
    Thanks a lot for the helpful info.

    Hello George / Viacheslav, thks to both for responding.
    BODS is based on 4.0 never was migrated from 3.2
    Under this repository almost 30 jobs currently running with no issues, which were created and scheduled before this error started.
    THis error message started just two months ago, since then it is not allowing any new jobs to be executed or creating any new schedules.
    But all prior jobs are running fine no issues.
    FRom designer i am able to execute with no problem, This issue is only happening on Mgmt console and only in this repository.
    Repository name has no apostrophe, all repsositories have the same style naming convention.
    "BODS_THENAME"
    Here i am pasting the block from viewsoure, where the error is:
     <span nowrap class="viewContext">Repository: BODS_JBROOK</span><table class="viewcontrollerarea" style="height:1"><COLGROUP><COL width="100%"/></COLGROUP><tr><td class="viewcontrollerheaderspacer"></td></tr><tr><td class="viewcontrollerheadertabarea"><table class="viewcontrollertabs"><tr class="viewcontrollertabs"><td class="viewcontrollertabs"><img border=0  src="../images/tab_sel_left.gif"></td><td class="selectedTab" nowrap background="../images/tab_sel_center.gif" ><a class="selectedTab"  href="/DataServices/servlet/AwBatchJobExecute?REPOSITORY_NAME=BODS_JBROOK&GUID=7cb34824-6d1f-42cc-9968-6c69d006ee87&NAME=Job_TestRaghuRepo&HISTORY=%2FDataServices%2Fservlet%2FAwBatchJobHistory%3FREPOSITORY_NAME%3DBODS_JBROOK%26SHOWREPO%3D2%26ACTIVE_VIEW%3DBatch%2BJob%2BConfiguration&ACTIVE_VIEW=Execute+Batch+Job">Execute Batch Job</a></td><td class="viewcontrollertabs"><img border=0  src="../images/tab_sel_right.gif"></td></tr></table></td></tr><tr bgcolor="#7997CD" ><td height="2px" class="viewfont" VALIGN=CENTER width="100%"></td></tr><tr><td class="viewcontrollermain"><div id="tipDiv" class="tipdiv"></div><span class="viewMessage">java.lang.NullPointerException</span><br><span class="viewMessage"> <!-- </span><br><span class="viewMessage">java.lang.NullPointerException at com.acta.repo.AwJobCommandOptions.getDBServerName(AwJobCommandOptions.java:322) at com.acta.repo.AwJobCommandOptions.getConnectionCmd(AwJobCommandOptions.java:388) at com.acta.repo.AwJobCommandOptions.getConnectionCmd(AwJobCommandOptions.java:379) at com.acta.repo.AwJobCommandOptions.validateConnectionInformation(AwJobCommandOptions.java:296) at com.acta.repo.AwJobCommandOptions.init(AwJobCommandOptions.java:168) at com.acta.repo.AwJobCommandOptions.<init>(AwJobCommandOptions.java:91) at com.acta.webapp.admin.report.AwExecuteBatchJobPage.submitAction(AwExecuteBatchJobPage.java:586) at com.acta.webapp.mdreport.common.DIView.doAction(DIView.java:564) at com.acta.webapp.mdreport.common.DIView.PrintReport(DIView.java:406) at com.acta.webapp.mdreport.common.DIViewController.PrintReport(DIViewController.java:84) at com.acta.webapp.mdreport.reportframework.JCActaGenericSection.PrintReport(JCActaGenericSection.java:112) at com.acta.webapp.mdreport.common.DIFrame.PrintReport(DIFrame.java:67) at com.acta.webapp.mdreport.common.DIMainFrame.PrintReport(DIMainFrame.java:98) at com.acta.webapp.mdreport.common.DIBaseReport.PrintMainFrame(DIBaseReport.java:233) at com.acta.webapp.mdreport.common.DIBaseReport.PrintReportImpl(DIBaseReport.java:158) at com.acta.webapp.mdreport.common.DIBaseReport.PrintReport(DIBaseReport.java:269) at com.acta.webapp.admin.servlet.AwBatchJobExecuteServlet.doPostSafe(AwBatchJobExecuteServlet.java:30) at com.acta.webapp.mdreport.reportframework.JSActaHttpServlet.doPost(JSActaHttpServlet.java:359) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.acta.webapp.mdreport.servlet.JSFilter.doFilter(JSFilter.java:71) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.acta.webapp.mdreport.servlet.EscapeFilter.doFilter(EscapeFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619)</span><br><span class="viewMessage"> --></span><br>

  • Now that I've isolated the problem...

    ...what exactly do I do next?
    My computer was crashing all the time in Tiger. Usually kernel panic sort of stuff. I upgraded to Leopard (archive and install), and it's gotten a bit better. But it still crashes much more than it should. I've isolated the problem -- basically, if I plug any USB or Firewire device in, I can expect a crash pretty soon, with the computer freezing up. (If I just plug in the keyboard, it seems to be OK. The printer is usually OK, but once or twice the computer has frozen up with just the keyboard and printer plugged in.)
    People always tell you to isolate the problem, which I've done. But the question is, what do you do next? I would've figured that installing a new System folder would've corrected the problem, but it hasn't. Of course, I can wipe the hard drive and put everything back on (I can occasionally get an external hard drive running without a freeze for long enough to run Time Machine), but why would that other stuff (aside from the System Folder) affect what I plug into the back of the computer?
    Anyway, I imagine I should do what I suggested above, right? Once I have a good recent Time Machine back-up, wipe the hard drive? Or is my computer just too old and underpowered (although that wouldn't explain all the crashes in Tiger, really)
    Thanks!

    Hey Barry,
    Appreciate your help. I archived and installed when I went to Leopard, so I don't think that'll help. And my drive is Verified in Disk Utility. I just plugged in my FireWire drive to do a Time Machine back-up, and the system crashed a few minutes later. Here's the log report:
    Wed Apr 9 16:00:26 2008
    Unresolved kernel trap(cpu 0): 0x300 - Data access DAR=0x00000000747344BD PC=0x00000000000362BC
    Latest crash info for cpu 0:
    Exception state (sv=0x1dbbe280)
    PC=0x000362BC; MSR=0x00001030; DAR=0x747344BD; DSISR=0x40000000; LR=0x000362BC; R1=0x1D7B3980; XCP=0x0000000C (0x300 - Data access)
    Backtrace:
    0x01D0F750 0x000369E4 0x00036BDC 0x0001EEC4 0x000249A0 0x002EA8C8
    0x000B05D4
    Proceeding back via exception chain:
    Exception state (sv=0x1dbbe280)
    previously dumped as "Latest" state. skipping...
    Exception state (sv=0xf74c80)
    PC=0x00000000; MSR=0x0000D030; DAR=0x00000000; DSISR=0x00000000; LR=0x00000000; R1=0x00000000; XCP=0x00000000 (Unknown)
    BSD process name corresponding to current thread: kernel_task
    Mac OS version:
    9C7010
    Kernel version:
    Darwin Kernel Version 9.2.2: Tue Mar 4 21:23:43 PST 2008; root:xnu-1228.4.31~1/RELEASE_PPC
    System model name: PowerMac6,3
    panic(cpu 0 caller 0xFFFF0003): 0x300 - Data access
    Latest stack backtrace for cpu 0:
    Backtrace:
    backtrace terminated - frame not mapped or invalid: 0x1D7B3680
    Proceeding back via exception chain:
    Exception state (sv=0x1dbbe280)
    PC=0x000362BC; MSR=0x00001030; DAR=0x747344BD; DSISR=0x40000000; LR=0x000362BC; R1=0x1D7B3980; XCP=0x0000000C (0x300 - Data access)
    Backtrace:
    backtrace terminated - frame not mapped or invalid: 0x1D7B3980
    Exception state (sv=0xf74c80)
    PC=0x00000000; MSR=0x0000D030; DAR=0x00000000; DSISR=0x00000000; LR=0x00000000; R1=0x00000000; XCP=0x00000000 (Unknown)
    Mean anything to you? I'm going to use Drive Genius to continue the search for the problem. You have any other ideas as to how I'd locate a hardware problem?
    Thanks again.

  • I Ipod class wont play TED and other video podcasts.  The genious bar could not figure out the problem.  This problem is not isolated to a single computer.  Secondly, the convert to ipod version feature in Itunes does not resolve the problem.

    My Ipod classic wont play TED, The Grid, Techzilla and other video podcasts (but not all video podcasts).  The genious bar could not figure out the problem. Instead, the Apple store gave me credit towards a new classic, which produced the same problem.  This problem is not isolated to a single computer.  Secondly, the convert to ipod version feature in Itunes does not resolve the problem.  Lastly, I tried restoring the ipod to no avail.  I've heard this is a video codec problem. 

    See this extensive older thread on the issue.
    https://discussions.apple.com/thread/2813428?start=45&tstart=0
    B-rock

Maybe you are looking for