Serialization vs Synchronization

Hello,
One concept of Serialization and Synchronization is one at a time, then how does they differ? In other words what is the difference between Serialization and Synchronization?
Thanking in advance.
With regards.
Muhammad Owais

If Synchronization is for mutual exclusion then can
you differentiate the following
object A is Synchronization
This makes no sense. No object is synchronization. You could create a class called Synchronization, but that would just be its name. There's nothing special about that word.
object B is ASynchronization
That's not even a word in Java.
object C is nither Synchronization nor
ASynchronization
Again, not making any sense.

Similar Messages

  • Diff between Serialization and Synchronization

    Hi I am new to java.
    Pl. give me the difference between Serialization and Synchronization.
    Thankq
    Sridhar

    Don't you look at the timestamps of posts? They could
    have been typing at the same time.
    /KajPlease stop! I'll die laughing. LOL
    Re: Diff between Serialization and Synchronization
    Author: Annie.   Apr 11, 2005 10:30 AM (reply 1 of 4)  
    Re: Diff between Serialization and Synchronization
    Author: glrao   Apr 12, 2005 8:31 AM (reply 2 of 4) I really like your sense of humor.
    xH4x0r

  • Serializable != Synchronization ???

    I am newbie to Serializable, for my understanding, if I implement Serializable, The jvm will treat the object as unique among distributed computing. but will the object
    treat the serializable object one by one like synchronization ????
    Any help is appreicated !!!

    >
    I am newbie to Serializable, for my understanding, if
    I implement Serializable, The jvm will treat the
    object as unique among distributed computing. but will
    the object treat the serializable object one by one like
    synchronization ????
    An object implementing Serializable simply notes that it is able to be serialized to a flat format commonly used to store objects in files, DB BLOB's and transfer between JVM's using RMI, etc.
    Serialized (i.e. one at a time access from multiple threads) is quite different, refered to in Java as synchronized and Java has no concept of a Class or Object being synchronized itself (although blocks of code or individual methods may be serialized against some object (the monitor used by Java).
    Chuck

  • Diff between Serialization and Synchonization

    Hi I am new to java.
    Pl. give me the difference between Serialization and Synchonization.
    Thankq
    Sridhar

    Pl. give me the difference between Serialization and
    Synchonization.Object serialization is the process of saving an object's state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time. The Java Serialization API provides a standard mechanism for developers to handle object serialization.
    Synchronization is intended to make the code thread safe by setting locks on objects.
    They are totally different concepts. I fail to understand how you intend to compare them.

  • POF compatibility across Coherence versions

    Dear all,
    I am very interested in using POF serialization to synchronize two Coherence grids via JMS for its performance and because the OO<->bytes serialization is already paid exchanging data between the business logic and the backing map.
    Before going in this direction, I would like to better understand POF characteristics (in addition to the wiki docs*) :
    - Will there be a POF compatibility between Coherence 3.5 and the forthcoming versions ?
    For example, will a POF written with Coherence 3.5.3 will be understandable by Coherence 3.6 ? 4.x ? Will the reverse be also true ? Will a POF written by Coherence 4.x be understandable by Coherence 3.5.3 ?
    - Is there a plan to make POF independant of Coherence ? Will it be possible to use POF in a pure weblogic-or-tomcat web app ? Will there be a downloadeable pof library with the associated licensing ?
    Thanks,
    Cyrille
    * http://coherence.oracle.com/display/COH35UG/The+Portable+Object+Format

    cyrille.leclerc wrote:
    Thanks for the insight Robert,
    Having such annotations in September would be very interesting for us.
    In addition to the classical *@Entity*, *@Basic*, *@Id*, *@IdClass*, I would like very much to have :
    * *@OneToMany* and *@OneToMany* to easily navigate in my partitionned entities (relations only possible between sub entities of the "root" entities that are put in the grid )
    * *@Version* for optimistic locking
    * AccessType field/getter in case I must do tricky things during my serialization
    * *@Index* to index fields declaratively
    * My super dream would be to have a *@Lob* annotation to tell the grid to store my very big fields with coherence transparently offloading this voluminous data outside of the heap memory and the RAM. I currently look at using a nio-file-manager style "lob-cache" just next to my "entity-cache" with colocalisation/keyassociation between the two.
    That was my whishlist :-)
    thanks again,
    Cyrille
    Cyrille Le Clerc
    [email protected]
    Hi Cyrille,
    my annotations do not work like JPA. The annotation processor which processes it just generates PofSerializers for them.
    Any kind of navigation-like code is totally orthogonal to them. Practically you can write your navigation code into your get methods (or implement them in utility methods and call on them from the getters) if you like (I don't usually like such coding style because it introduces the n+1 problem), and annotate your to-be-serialized attributes and the annotation processor takes care of generating PofSerializer implementations during build time.
    Obviously, for the .NET/C++ artifacts, some additional customizability needs to be introduced to reproduce such navigation methods you may have, but that is still the future, and I don't see that such a critical feature. I don't really like resource modification code in data class operations. It brings back the days of EJB 1 Entity beans again.
    The @Index annotation could be taken care of by another annotation processor which may or may not be aware of my POF Serializer runtime library, although I do see added value in integrating such indexing support into the generator (generate proper extractors leveraging certain features of my attribute serializers)
    What you mentioned for AccessType is likely supported by the existing serializer annotations (pre/post serialization/deserialization hooks, getter/direct field access, immutable factory class support for deserialization).
    For blob you should also look at nio-memory-manager and partition-aware backing maps (it increases the total NIO memory you can leverage).
    Best regards,
    Robert

  • Serialization, Synchronization, Deadlock?

    When the serialization routine traverses a complex graph of objects, does it call writeObject recursively, or iteratively? (Is 'iteratively' a word?)
    If it's recursive, synchronized writeObject methods could deadlock if another thread is synchronized on more than one object in the graph, right?

    Yes, writeObject() is called recursively [how else can this work?]. The possibility of a deadlock is real. Just like in any other code where you have concurrent access to shared data and use synchronization.

  • How do you synchroniz​e accesses to a LabVIEW Shared Variable?

    I would like to create an ad-hoc weather station program (I'll explain more in a bit).  I am using LabVIEW 8.0 Full Edition, and I would like to share data over a network between stations with the LabVIEW Shared Variable.  Here's what I want to be able to do:
    A node would start up, and begin publishing data to a network via a shared variable.
    The shared variable is an array of clusters
    The cluster information would hold things like:
    Station Name
    Station Location
    Weather information cluster (temperature, rainfall, windspeed, wind direction, etc...)
    Timestamp of last update
    When a new node would like to enter, it would bind to the shared variable, grow the array, and add its information.
    If a node's Station Name and Station Location is already in the shared variable, it would merely update the information in the cluster.
    Viewing nodes could pop in, bind to the shared variable, and read/display the information at any time. 
    I am trying to enumerate problems with this before implementing, and I have run into a stinker of a problem that I am not sure how to solve.  How do I synchronize accesses to the LabVIEW Shared Variable?  If I read the variable, modify it, and write it back, I will undoubtedly run into a race condition where 2 nodes attempt to update its data and I will lose the data written by the first node - Node A reads, Node A modifies, Node B reads, Node A writes, Node B Modifies, Node B Writes, and thus the modifications made by Node A are lost.  In my specific application losing some data isn't critical, but if not remedied this type of problem could cause massive amounts of data to be lost when there are numerous nodes, and that is definitely not acceptable. 
    Does anyone have any recommendations on how to synchronize the read-modify-write operations on the data in the Shared Variable?
    -Danny

    Wendy,
    I am afraid Semaphores are not network-shared objects (to my knowledge), they are system-level objects that use operating-system synchronization mechanisms.  If I were synchronizing on a single machine, a semaphore might be a valid mechanism; as an aside, most user-mode semaphores are designed to synchronize within a single process - to synchronize between processes you need to store the semaphore in the Kernel, and to synchronize over a network you would need a network node to handle serialization of requests.  My Shared Variable is published over a network, and to my knowledge there are no network-published synchronization mechanisms available - mostly because there is no way to currently perform an atomic test-and-set on the Shared Variable (am I correct?) and there isn't a mechanism for blocking access to a Shared Variable from another network device/machine (or is there?).  I've been looking for some way to implement an atomic test-and-set but I am running into a wall; I know that if I select the "single writer" attribute of the Shared Variable I can get LabVIEW to force a single writer allowing me to have an atomic "set", but I need more than that.
    If only there was a network-shared Semaphore or some way to block other network accesses to the Shared Variable I would be in business - something like what I want doesn't exist, does it?
    Thanks!
    -Danny
    Message Edited by texasdiaz on 02-23-2006 02:52 AM

  • Is a Servlet-Filter which serializes requests in the same user session ok?

    The Servelt specification states that the Web-Application is itself responsible for synchronizing access to HttpSessions. It is from the serversite not possible to prevent multiple threads to access the same HttpSession (i.e. the user could always open a second window, retransmit a form etc). My assumption is that while this does not happen often it can happen and therefore I think each access to the HttpSession must be synchronized. For a further discussion see http://forum.java.sun.com/thread.jsp?forum=4&thread=169872 .
    Concurrent programming is generally complicated and errorprone. At least in developing JSPs it is inconvenient and easy to forget. My Web-App uses often HttpSession and it can be used in different not predefined places, so I had the idea to implement a ServletFilter which serializes threads which happen in the same session. This involves certainly some overhead. However for the advantages of easier code maintains and higher consistency I am ready to pay this overhead.
    My question is generally what you think of this approach and second whether the way I implemented the Filter works.
    The Filter actually generates for each Request an HttpServletRequestWrapper which intercepts calls to getSession and on call aquires a Lock so that other threads have to wait for the same Session. The lock is released when the doFilter method of the Filter returns. So threads run concurrently until the first access to the Session and from there they are serialized until the end of the Request.
    For the details I will give the code for the Filter and the Wrapper (that?s all the code needed except the ReentrantLock which is Doug Lea?s implementation http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html )
    the Filter
    public class SessionThreadFilter implements Filter
      public static final String MUTEXT_IN_SESSION_KEY = "org.jaul.filter.SessionThreadFilter.MUTEX";
      //constructor, init, destroy methods do nothing
      public void doFilter(ServletRequest reqIn,ServletResponse res,FilterChain filterChain)
        throws IOException, ServletException
        //if req not instanceof of HttpRequest don't do anything
        if (!(reqIn instanceof HttpServletRequest))
          filterChain.doFilter(reqIn, res);
        } else
          HttpServletRequest req = (HttpServletRequest) reqIn;
          //We use a HttpRequestWrapper each time a user accesses
          //through this
          //Wrapper a Session is Lock is aquired. The filter method returns
          //the lock if it exists is released
          //each thread needs it's own wrapper so the wrapper itself
          //doesn't have to be synchronized
          SessionThreadRequestWrapper wrapper = new SessionThreadRequestWrapper(req);
          try{
            filterChain.doFilter(wrapper, res);
          }finally{
            ReentrantLock lock = wrapper.getLock();
            if (lock != null && lock.holds() != 0)
                       lock.release(lock.holds());
    the Wrapper
    final public class SessionThreadRequestWrapper extends HttpServletRequestWrapper {
      private ReentrantLock lock = null;
       * Constructor for SessionThreadRequestWrapper.
       * @param arg0
      public SessionThreadRequestWrapper(HttpServletRequest req){
        super(req);
       * @see javax.servlet.http.HttpServletRequest#getSession()
      public HttpSession getSession(){
        return getSession(true);
       * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
      public HttpSession getSession(boolean construct){
        //this will get the session an the lock
        HttpSession session = getLockFromSession(construct);
        if (session == null) return null;
        //get a lock on the mutex
        try{
          lock.acquire();
        } catch (InterruptedException e){
          throw new IllegalStateException("Interrupted while thread waiting for session");
        //now we check again if the session is still valid
        try{
          session.getAttribute(SessionThreadFilter.MUTEXT_IN_SESSION_KEY);
        } catch (IllegalStateException e){
          //again we go recusively but first release the lock
          lock.release();
          lock = null;
          return getSession(construct);
        //after you got the lock you can return the session
        return session;
       * gets the lock from the session
       * @param construct
       * @return HttpSession
      private HttpSession getLockFromSession(boolean construct){
        //test if it is a new Session
        HttpSession session = super.getSession(construct);
        //if is null no session was realy requested
        if (session == null) return null;
        //otherwise try to get the lock if necessery construct it
        //syncrhonized over session
        synchronized (session){
          //this migth throw an Exception if the session has been
          //invalidated in the mean time
          try{
            lock = (ReentrantLock) session.getAttribute(SessionThreadFilter.MUTEXT_IN_SESSION_KEY);
            if (lock == null){
              lock = new ReentrantLock();
              session.setAttribute (SessionThreadFilter.MUTEXT_IN_SESSION_KEY, lock);
            return session;
          } catch (IllegalStateException e){
            //the session has been invalidated before we tried to get the
            //lock we recursively call getLockFromSession
            //( assumption checked with Jetty: if the session is invalidated
            //and getSession is called on the thread a new valid session
            // should is returend)
            //I hope sometime you should get a valid session but I am not
            //sure. This is crucial for breaking of the recursion
            lock = null;
            return this.getLockFromSession(construct);
      /** used by the Filter to get the lock so that it can release it
      ReentrantLock getLock(){
         return this.lock;
    }As stated I would be very thankful if you could check the code and give some commends.

    synchronized (session){Are you sure that the session instance returned by two
    concurrent calls to getSession(...) are the same? I
    think that tomcat for instance may return different
    instances for the same "logical " session, which would
    break your scheme I think... Thank you (I did not know that on Tomcat). The same thing could also occur if another filter wrapped the Session.
    That's indeed a problem,which I have already adressed in another thread, but did not get an answer. ( http://forum.java.sun.com/thread.jsp?forum=33&thread=412380). The already cited thread http://forum.java.sun.com/thread.jsp?forum=4&thread=169872 adresses the same problem, but the discussion there ends with the recomandation that you should synchronize on HttpSession as I did it. Also in other forums I've read so.
    However like you I've at least strong doubts in this approach, so now my question is on what should I than generally for any access in any web-app syncrhonize the access to Http-Session as demanded by the Servlet specs.
    A few not realy satisfying answers:
    Synchronize on the HttpSession itself: I think still the best approach, but as you say is it guaranteed that the same instance of an HttpSession is given to each Request (in one Session)?
    Synchronized on the HttpServlet: This only works if no other servlet (or jsp) accesses in the session the value with the same key ( of course only if the session itself is threadsave). In case of ThingleThread it is not possible at all there can be multiple instances (you could use a static variable)
    Holding the object to synchronize on in applicaton scope or session scope: This obiously doesn't help, because somehow you have to obtain the lock and at least there you need another synchronize.Holding in application socpe is slow a static variable lock would be better there.
    Synchronize on some static variable: This will work, but is very slow (each request not only in the same session would synchronize on this).
    Hold a map in application scope, which holds for each Session-key a lock: Is probably faster than the static variable thing. However the access and the management of the Map (removing of unused locks etc.- Mabe you could use a WeakHashMap to collect the locks for not used keys anymore) is time consuming too and again the map must be accessed syncrhonasly by all requests.
    Syncrhonize on the Filter (only in my case): This is as slow as the static variable approach because each request will use the same lock the one instance of the Filter.
    So synchronizing on the session is propably the best approach if the same attribute name is accesed by different servlets. However if you say that some Web-Containers return different HttpSession instances for the same Session (which is legal according to the specification) this of course does not work.
    So I have realy no clue on what to syncrhonize than. Now help is not only neede on my Thread serialization filter but on my generally Servlet prgromming.
    May be you could help me for another synchronization aproach.

  • Custom "serializer" in ReplicatedCache not set on CacheHandler

    I tried to configure custom Serializer on ReplicatedCache service (supposed to be new feature in Coherence 3.4) in tangosol-coherence-override.xml like this:
    <coherence>
    <cluster-config>
    <services>
    <service id="1">
    <service-type>ReplicatedCache</service-type>
    <service-component>ReplicatedCache</service-component>
    <init-params>
    <init-param id="5">
    <param-name>serializer/class-name</param-name>
    <param-value>com.marand.cache.io.ThinTypeMapSerializer</param-value>
    </init-param>
    </init-params>
    </service>
    </services>
    </cluster-config>
    </coherence>
    ... and it is actually being picked up and used, but as soon as starting 2nd node in a cluster, when it should synchronize the replicated caches, I get an Exception:
    java.lang.ClassCastException: com.marand.cache.io.ThinTypeMapSerializer cannot be cast to com.tangosol.io.DefaultSerializer
         at com.tangosol.util.ExternalizableHelper.deserializeInternal(ExternalizableHelper.java:2643)
         at com.tangosol.util.ExternalizableHelper.fromBinary(ExternalizableHelper.java:256)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache$ConverterFromInternal.convert(ReplicatedCache.CDB:6)
         at com.tangosol.util.ConverterCollections$ConverterMapEvent.getNewValue(ConverterCollections.java:3594)
         at com.tangosol.coherence.component.util.cacheHandler.CatalogHandler.entryInserted(CatalogHandler.CDB:3)
         at com.tangosol.util.MapEvent.dispatch(MapEvent.java:191)
         at com.tangosol.util.MapEvent.dispatch(MapEvent.java:164)
         at com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
         at com.tangosol.coherence.component.util.CacheHandler.onLeaseUpdate(CacheHandler.CDB:83)
         at com.tangosol.coherence.component.util.CacheHandler.populateCache(CacheHandler.CDB:33)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache$CacheUpdate.onReceived(ReplicatedCache.CDB:5)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onMessage(Grid.CDB:9)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:130)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.onNotify(ReplicatedCache.CDB:3)
         at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:37)
         at java.lang.Thread.run(Thread.java:619)
    ...Investigating further I found that the deserialization works correctly - the ReplicatedCache$ConverterFromInternal is actually using the custom Serializer when
    trying to deserialize the ReplicatedCache$CacheUpdate message. But the sending node constructs the ReplicatedCache$CacheUpdate message and populates it using the CacheHandler.populateUpdateMessage method which in turn uses the CacheHandler's serializer and that is not being set in the process of initialization - see the following methods:
    ReplicatedCache.instantiateCacheHandler & ReplicatedCache.cloneCacheHandler
    Am I correct that this is a bug?
    Peter

    Unfortunately DefaultSerializer is final ;-(
    ...I think that CatalogHandler (a subclass of CacheHandler) which is also being used as the 1st handler in ReplicatedCache is the right suspect. This is definitely always using DefaultSerializer.

  • Serialization Clarification

    I am creating a wizard application that allows the user to enter a fair amount of data then run a simulation based on that data.
    Now, I want to save all of the information the user puts in via sliders, textfields, radio buttons, check boxes, Jtables, graphs, ect. I've been trying to figure out the best way to do this and I think serialization may help me but I'm not sure. All of the user input is done via Swing components.
    Now the way I'm thinking I should do this is:
    1. create a class that can get all of the user input values from the Swing components. (can also set the swing components)
    2. make that class serializable (ie I get an array or a table model)
    3. write that class out.
    4. be able to load that class back in and have it set all of the swing components.
    Where I get a little confused here is that most Swing components are serializable so should I just be getting and setting the components themselves? or their values? Because if I got and set the components themselves, couldn't I then just get each JPanel that contains all of the components and reload the JPanel? Would I lose the values for each component?
    I'm a bit confused and would greatly appreciate a point in the right direction.

    Thanks, this is proving to be a very enlightening expierence.
    I started with a confusion about synchronization, and that is cleared up a bit now, but now I'm beginning to think I'm going about this wrong?
    Here's the situation:
    I've got a Swing GUI. That is it. The components are in place, nothing further. No Listeners yet.
    The GUI is designed to be a wizard that guides the user through entering some information through various components(JTextfield, JSlider, JTable, ect.)
    At the end of the wizard, the program uses the information the user entered to simulate/model what could happen.
    The program then displays the output.
    What would be the best way to save all of the user entered information?
    With that, and reading a bit about MVC, my impression is that:
    M = user input + other hidden values calculated from user input and all of the logic
    V = GUI components
    C = listeners
    I'm not really sure that the above is the right idea either? It seems to make sense that the Model is seperate from everything and can operate without the GUI. Then the GUI is just a place for the user to enter information. And the controller tells the model when to do things based on changes in the view or tells the view to change based on changes in the model correct?
    So if that's right, then I think where I am getting lost is what is the best way to save the model? So step by step:
    1: initialize the model
    2: have controller update the view with the initial values
    3. change a value in the view
    4. contoller changes that value in the model
    5. write the model data to a file
    6. load the model data.
    7. controller updates view from new model values.
    The problem with the above then would be that the swing components have listeners that make updating the model from the view easy, but then would I have to register some sort of listener on the model to update the view(swing components)?
    Sorry for the long messages but it helps me think through things and hopefully helps to point out any errors in my thoughts.
    Thanks again for all the help, this is really helping me to understand.

  • Server design (multithreading, serialization, and performance)

    (I'm not asking for anyone to design my software for me, I'm just looking for a response along the lines of "That's called XYZ server design, look for books on this topic" sort of thing.)
    Summary:
    I have a Server application (S) that accepts connections from many Clients (C). The clients request pieces of a large internal data structure, *"Data"* (D). The clients are totally passive with respect to Data, they only read (from the Server) and do not initiate any modification.
    D is really a structure of structures: it's hashtables of hashtables, with objects that hold other hashtables and vectors, etc. etc., down a few levels. The clients don't read the entire structure, just parts of it.
    The Server is multi-threaded, with threads handling client communications, and a very important thread that modifies Data by processing messages from an external source. I call this part of the software the Message Processor (P). These messages are what drives manipulation of the data structure.
    [**CLICK HERE FOR A DIAGRAM**|http://imgur.com/sb5ZU]
    There are a couple of design questions I'm wondering about:
    The data structure D is a shared resource between the Client threads and the Message Processor thread within the Server, with the Client threads only reading from the data structure (and writing over TCP/IP), and the Message Processor both reading and modifying it.
    Right now I am using locks to lock the structure when a client requests data, so that the processor cannot modify the data while it is being serialized.
    I also lock the data structure when a message is received and the structure has to be modified by P, to prevent the structure from being serialized while it is being modified.
    My question is, is this the only design pattern I can use in this situation? It looks like the only way to improve performance is to
    a) make sure I only lock when necessary (to prevent data corruption or inconsistency)
    b) lock the data for as short a time as possible
    c) make sure the parts of the data structure being sent to clients are serialized as fast as possible (write my own writeObject/readObject methods)
    Any insight is appreciated, the shorter and more candid, the better. Don't be afraid to say I'm in over my head and should read a few books by author so-and-so, that's a good starting point :)

    jta23 wrote:
    (I'm not asking for anyone to design my software for me, I'm just looking for a response along the lines of "That's called XYZ server design, look for books on this topic" sort of thing.)
    Summary:
    I have a Server application (S) that accepts connections from many Clients (C). The clients request pieces of a large internal data structure, *"Data"* (D). The clients are totally passive with respect to Data, they only read (from the Server) and do not initiate any modification.
    Are you using Servlets? That should facilitate the development of your server immensely (e.g., maintains sessions, handles multi-threading, implements HTTP out of the box, dozens of additional frameworks available, etc.)
    D is really a structure of structures: it's hashtables of hashtables, with objects that hold other hashtables and vectors, etc. etc., down a few levels. The clients don't read the entire structure, just parts of it.
    You can get away with using Map of Map or Map of List or whatever level of nesting you want. Generally, however, it is better to implement a canonical and rich domain model. [http://www.eaipatterns.com/CanonicalDataModel.html]. [http://www.substanceofcode.com/2007/01/17/from-anemic-to-rich-domain-model/].
    The Server is multi-threaded, with threads handling client communications, and a very important thread that modifies Data by processing messages from an external source. I call this part of the software the Message Processor (P). These messages are what drives manipulation of the data structure.
    [**CLICK HERE FOR A DIAGRAM**|http://imgur.com/sb5ZU]
    There are a couple of design questions I'm wondering about:
    The data structure D is a shared resource between the Client threads and the Message Processor thread within the Server, with the Client threads only reading from the data structure (and writing over TCP/IP), and the Message Processor both reading and modifying it.
    Right now I am using locks to lock the structure when a client requests data, so that the processor cannot modify the data while it is being serialized.
    I also lock the data structure when a message is received and the structure has to be modified by P, to prevent the structure from being serialized while it is being modified.
    My question is, is this the only design pattern I can use in this situation? It looks like the only way to improve performance is to
    a) make sure I only lock when necessary (to prevent data corruption or inconsistency)This can easily be handled by a Servlet. I think the best way to do this would be to create a Singleton. [www.javacoffeebreak.com/articles/designpatterns/index.html]. Be careful, however. Singletons are like global variables. They can easily be abused. If you did not want a singleton, create a lock table in your database. The RDBMS will handle synchronization for you, and it is an elegant solution. You can perform a similar feat using a filesystem lock that you create. Up to you. Whether in the JVM, in the database or in the filesystem.
    b) lock the data for as short a time as possibleWrite an efficient method to insert or update or delete the data. If you are dealing with a large amount of data, consider using a native tool like Oracle's SqlLoader or using vendor-specific JDBC syntax. If you need to support multiple types of databases, use bulk JDBC operations.
    c) make sure the parts of the data structure being sent to clients are serialized as fast as possible (write my own writeObject/readObject methods)
    Take a look at JBoss serialization. It is much more compact that Java's. Or do some experimenting. JSON is much more compact than XML normally, and it can be read by a Javascript client to facilitate any Ajax you might want to use for some flash and sizzle.
    Any insight is appreciated, the shorter and more candid, the better. Don't be afraid to say I'm in over my head and should read a few books by author so-and-so, that's a good starting point :)No, take it in bite sized pieces. Start with the server. Then work on the client. Play around with your locking strategy. Optimize your update of the data. Don't do everything at once.
    - Saish

  • Serialization and Concurrency

    My application uses a data store consisting of several arrays of serializable objects inside a container class. To save the database I simply serialize the container object.
    The get/set methods on the data objects are synchronized. Various threads could attempt to access these objects while the object containing them is being serialized.
    What happens if, during serialization, one of the objects already serialized is modified? Will the serialization throw an exception? Will the updated object be written into the stream? Or will it silently fail, potentially introducing inconsistencies into my database?
    To prevent this, I'm considering synchronizing the data objects' get/set methods on a common mutex, which I could then lock for serialization. Will this work? (I know it could be a performance bottleneck, but this isn't a high-load app.)
    And by the way, if it does work, would it still be necessary to synchronize on the individial objects? I don't think so, but I just wanna make sure.
    Thanks,
    Krum

    Hello Krum,
    Interesting problem - simple however, :D
    Your problem is that you do not want the state of the object to change while it is being serialized, as it might lead to inconsistency (serialization will not throw any exception even if the values change).
    implement private void writeObject(java.io.ObjectOutputStream stream)
    throws IOException;
    on all the classes and synchronize set/writeObject methods. From within the writeObject call ObjectOutputStream.defaultWriteObject();
    Should prevent inconcistency.

  • How can I synchronize all hotmail folders in Mac's "Mail"? (Not just Inbox)

    I tried to synchronize my hotmail accounts in Mac's Mail but only those emails inside "Inbox" can be synchronized. No other folders under my hotmail can be synchronized. Is there any tools to solve this problem?

    If you right click on a son in iTunes and click Get Info. Under the Sorting tab iyo can change how the songs is sorted in iTunes
    Tips for using song and CD info to organize your music
    You can edit information in the Info window to make it easier to find and sort items in your library. For example, you can:
    Group individual movements on a classical CD into one work by indicating the name of the work (for example, “Piano concerto in A Minor, Op. 54”) in the Grouping field.
    Group songs that are part of a compilation together in your library by clicking Details and selecting the checkbox next to “Album is a compilation of songs by various artists”.
    Identify the individual artists on a tribute album in the Artist field, and type “various” in the Album Artist field.
    Create your own genre category by clicking Details and typing the category in the Genre field.
    Change the order in which tracks on a CD play by changing the numbers in the Track fields.
    Create a Smart Playlist that includes only songs that are just the right speed for your workout by typing the number of beats per minute in the BPM field. For instructions, see Create a Smart Playlist.
    Identify a movie as a music video (click the Options button, and choose Music Video from the Media Kind pop-up menu).
    Identify an item that you imported from a CD as an audiobook, so it appears under Audiobooks instead of Music (click the Options button and choose Audiobook from the Media Kind pop-up menu). If you do this, iTunes also remembers your place in the audiobook.
    Enter custom sorting criteria for an item. Select the item, choose File > Get Info, click Sorting, and enter the custom text.
    Does the non-syncing songs play in iTunes on the computer?
    is there anything different about the songs that do sync and those that do not? Like where they cam from? The format (Get Info>under the File tab).

  • How do I add my Hotmail account to my Mail app on my MacBook Pro so that it synchronize automatically ?

    Hi guys, I'm new to Mac. I know that you can add email accounts likeHotmail into your Mail app so that you can view, edit, modify, create and delete your emails and folders, etc. The questions I have are (1) can I see all the emails I have not just in the inbox but all the other folders as well just like if I was logging on to Hotmail via Internet Explorer ? (2) what happens if I read some emails, delete or move some emails, create new emails and send or save in draft, create or delete folders, etc in the Mail app on my MacBook Pro, will this synchronize and reflect the same on my Hotmail account if I was to logging via Internet Explorer ? How about the other way ? If so, how do I set it up on my MacBook Pro to do this automatically ?
    I know that this doesn't work with Hotmail accounts on my iPhone 4 via the Mail app. Everytime I read an email or delete an email on my Mail app, it does not synchronize or reflect the same on my live Hotmail account when I logging via Internet Explorer.
    Any help, guidance or advise would be appreciated. Thanks.

    Edit: never mind, I was using the wrong password

  • Hello, My iCal don't synchronize older events than two or three month ago. How can I do to synchronize all my schedule? In iTunes it's all right in Calendars. I don't put a cross in "synchronize event older than ....... days". Thanks for answer.

    Hello, My iCal don't synchronize older events than two or three month ago. How can I do to synchronize all my schedule? In iTunes it's all right in Calendars. I don't put a cross in "synchronize event older than ....... days". Thanks for answer.

    Just saw your post. Better late than never. You may want to
    consider GameBrix.com, where you can create Flash based, casual
    games using your web browser. No downloads are required. You can
    create a game from scratch using a library of images, sounds and
    game mechanics. You can also upload your own. The online script
    editor will allow you to view and edit the ActionScripts associated
    with each game mechanic. In short, a great way to ramp up on game
    design and build your own game without investing a lot of $
    upfront.
    BTW I am associated with GameBrix so any feedback is
    appreciated.

Maybe you are looking for