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.
Similar Messages
-
MTS with batch management, serialization and Handling unit
Hello All,
I am testing a scenario for MTS with batch management, serialization and Handling unit for discrete manufacturing.
Everything worked fine till I created the Handling unit for the finished product.
The production order has a quantity of 3 EA.
It has three serial numbers 1, 2 and 3. (serial numbers can be displayed from order->Header->serial numbers)
I created one Handling unit for production order quantity of 3 EA.
I tried to do a goods receipt for the production order using transaction COWBHUWE.
I get the following error when I try to post the GR:
Only 0 serial numbers entered instead of 3
Message no. IO304
Diagnosis
There is a serial number obligation, so the number of serial numbers must equal the number of serial numbers in the material document.
You can post the operation only if you entered the correct number of serial numbers previously.
System Response
Depending on the context in which the error arises, the system continues processing, or the required function cannot be performed.
Procedure
You have the following options, for example:
Check that the serial numbers are entered fully.
If necessary, display an error log.
If necessary, contact your system administrator.
What did I miss?
How to fix this problem?
Please help.
Thanks in advance
GeorgeI added the serialization procedure HUSL to the serial number profile and it fixed the problem.
-
Revision: 22429
Revision: 22429
Author: [email protected]
Date: 2011-09-07 08:04:46 -0700 (Wed, 07 Sep 2011)
Log Message:
Adding the default fallback of serializer and deserializer classes to amf deserializer and amf serializer
Modified Paths:
blazeds/trunk/modules/core/src/flex/messaging/io/SerializationContext.java -
Diff between Serialization and Synchronization
Hi I am new to java.
Pl. give me the difference between Serialization and Synchronization.
Thankq
SridharDon'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 -
Diff between Serialization and Synchonization
Hi I am new to java.
Pl. give me the difference between Serialization and Synchonization.
Thankq
SridharPl. 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. -
Singleton serialization and weblogic - help!
hi everyone,
I'm trying to serialize a singleton cache object we're using for our (intranet)
website running on weblogic 6.1. I've made sure the singleton class
implements serializable, and i've also put the following method in the
singleton class (ChartCache.java):
private Object readResolve()
return theInstance; //which is of type ChartCache
By the way I'm using jdk 1.3. I've trawled the web and can't find anything to help me yet...
Basically I've written a jsp to get the current instance of the cache
and serialize it to a file. When I invoke another jsp i want it to
reinflate the object and place it back into the weblogic jvm so it can
once again be accessed as a singleton by all classes in the webapp. At
the moment its just not working - the cache object will eventually
take over half an hour to create (huge database processing going on)
so I want the option, if weblogic falls over, to reinstantiate the
cache without having to rebuild it from scratch. The cache will only
be refreshed once a day.
I'll c&p my jsp code below...
======================= restoreCache.jsp
<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "com.drkw.agencylending.website.chartcache.*" %>
<%@ page import = "com.drkw.agencylending.log.Logger" %>
<%
ChartCache theCache = null;
try
String filename = "chartCache.dat";
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fis);
theCache = (ChartCache)in.readObject();
in.close();
catch(Exception e)
Logger.log(e);
%>
Resurrected chart cache from file.
======================= saveCache.jsp
<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "com.drkw.agencylending.website.chartcache.*" %>
<%@ page import = "com.drkw.agencylending.log.Logger" %>
<%
ChartCache theCache = ChartCache.getInstance();
String fileName = "chartCache.dat";
try
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(theCache);
oos.flush();
oos.close();
catch(Exception e)
Logger.log(e);
%>
Wrote cache object to file.
============================
At the moment, a file is getting written but it seems suspiciously
small (73 bytes!) for what is a very large object. When I try to load
it up again, I get no errors but when I call ChartCache.getInstance()
(my singleton) it recreates the cache rather than using the one I've
reinflated. BTW I don't need to worry about server clustering/JNDI to
ensure I have a truly singleton instance - there will only ever be one
JVM to worry about.
Any help greatly appreciated!solved the problem using another technique. Rather
than serialize the entire singleton object, I just
serialized the hashmap (the only bit I really care
about). Then in the private constructor, the class
checks a database flag to see whether the singleton
was created today - if not, I refresh the cache,
otherwise load in the serialized hashmap and set that
as my class member. No complicated jndi/ejb registry
needed to get around it..!singleton serialization is not recommended in ejb enviroment, it will cause problems. in what you are doing, it is far better to persist the data values in a database.
just for the sake of writing a serializable sington: in addition to what you do in a regular object, you would first check to see if this obj has been serialized, if it is, deserialize it and return this one. you would have to write your own method to do serialization, making sure you have only one place to serialize it, and let the object know where the file is. -
Weak and concurrent hash map for caching
Hello,
I have written a very simple cache class with both weakness and concurrency benefits. This class is intended to be used as a weak cache in "hot redeploy" capable servers (JBoss or any other).
My implementation uses the (problematic) "double-check" pattern with a reentrant lock and encapsulates a WeakHashMap with WeakReference values (to avoid circular key/value references). Here is the code:
public interface ValueCreator<V> {
public V create();
public class WeakCache<K, V> {
private final Lock lock = new ReentrantLock();
private final Map<K, WeakReference<V>> weakMap;
public WeakCache() {
this(16);
public WeakCache(int initialCapacity) {
this(initialCapacity, 0.75F);
public WeakCache(int initialCapacity, float loadFactor) {
weakMap = new WeakHashMap<K, WeakReference<V>>(initialCapacity, loadFactor);
public V get(K key, ValueCreator<V> creator) {
WeakReference<V> ref = weakMap.get(key);
if (ref == null) {
lock.lock();
try {
ref = weakMap.get(key);
if (ref == null) {
ref = new WeakReference<V>(creator.create());
weakMap.put(key, ref);
} finally {
lock.unlock();
return ref.get();
}One usage of this cache is for session ejb3 lookup:
private static final WeakCache<Class, Object> LOOKUP_CACHE = new WeakCache<Class, Object>();
public static <T> T lookup(final Class<T> serviceClass) {
T service = (T)LOOKUP_CACHE.get(serviceClass,
new ValueCreator<Object>() {
public T create() {
String lookup = "myapp/" + serviceClass.getSimpleName() + "/local";
try {
return (T)(new InitialContext()).lookup(lookup);
} catch (NamingException e) {
throw new RuntimeException("Could not lookup EJB " + serviceClass + ": " + lookup, e);
return service;
...2 questions:
1. Is there any issue with concurrent access to this cache ?
2. What happens exactly when the garbage collector wants to free memory with a map with both weak keys and values ?
Some limited tests show that the behavior of this cache fits my needs: the lookup cache is cleared on redeploy and it keeps its key/values pairs otherwise.
Thanks for any comments.
Message was edited by:
fwolff999I know that DCL is broken under certain circumstances (but I have read it may work with modern JVM and the use of volatile variables for example).
So: is it broken with this specific implementation and if so, what should be done to make it work ?
The getter method is potentially setting a value (like in ConcurrentHashMap.putIfAbsent) and it uses a ValueCreator in order to actually create the value only if it is not already present in the map. -
Using serialize and deserialize methods generated by clientgen
I am trying to use the classes generated by the weblogic.webservice.clientgen tool
from the weblogic 8.1 release. I would like to be able to make direct use of
the serialize and
deserialize methods in the "Codec" classes that correspond to the various request
and
response object classes. However, these methods require SerializationContext
and
deserializationContext objects as inputs. Are these context objects things I
can construct,
manufacture and/or access? Are there any coding examples for using these methods?
Thanks.
MichaelBruce,
Thanks for the response. I have seen the documentation before. What that shows
me is how
to write customized Serialize and Deserialize methods. What I want to do is call
the ones that
clientgen has already created for me. I would love to have these called by the
internals of the
generated code as part of the handling of service calls. My problem is that the
web site
that I'm calling for these services uses SSL, and every attempt to use the clientgen-generated
services results in the following exception being raised:
javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable
certificate was received.
Since I am successful in making SOAP calls to this same site -- certificate aren't
an issue
for these SOAP calls -- I thought that what I should try is to make the service
calls myself
using SOAP, but to use the generated Serialize and Deserialize methods
to create the request body and process the response body surrounding the SOAP
call.
However, what I'd really like to do
is figure out the cause of the SSLKeyException, and to make the service calls
the way weblogic
intended them to be made. So if you have any suggestions about what might
be causing the exception, I'd appreciate the help.
BTW. In addition to being able to make SOAP calls myself, I've also had some success
making
web service calls using code generated by Apache AXIS's wsdl2java tool and JWSDP's
wscompile
tool; however, neither of these wsdl processors are replacements for clientgen
because they
both have problems dealing with the complex structures described by wsdl files
for the web
services I'm trying to use.
Bruce Stephens <[email protected]> wrote:
Hi Michael,
The De/SerializationContext are internal/private objects. The example
in the doc (you have probably already seen) is a good starting point:
http://e-docs.bea.com/wls/docs81/webserv/customdata.html#1052981
Regards,
Bruce
BTW, Have you considered using XMLBeans?
http://dev2dev.bea.com/technologies/xmlbeans/index.jsp
Michael Horton wrote:
I am trying to use the classes generated by the weblogic.webservice.clientgentool
from the weblogic 8.1 release. I would like to be able to make directuse of
the serialize and
deserialize methods in the "Codec" classes that correspond to the variousrequest
and
response object classes. However, these methods require SerializationContext
and
deserializationContext objects as inputs. Are these context objectsthings I
can construct,
manufacture and/or access? Are there any coding examples for usingthese methods?
Thanks.
Michael -
RMI and concurrency (newbie)
Hi
I have a simple question related to RMI and concurrency.
I have a server and several clients calling remote objects concurrently.
How is concurrency usually handled when one used RMI ?
Can we make use of "synchronized" on some method of the remote objects ?
I have read about risk related to performance and worse, some problems of deadlock if the synchronize is not well organized.
Is there other ways to deal with that ?
Thanks in advance for providinge me any information or suggestion.RMI is inherently multithreaded. If you have specific remote resources that you want protected from concurrency, then define all of the accessor methods to be synchronized. (I don't think you can get away with making the remote methods synchronized; I would instead figure out what which resources I want to protect, and only protect those particular objects.)
Could there be problems? Maybe. But these are absolutely standard coding techniques. -
Regarding Serializable and subclasses.
I have a an abstract parent class called 'Information'
which implements Serializable and which has an abstract
method called init().
There are 2 subclasses that extend the parent class Information
called SInformation_1 and SInformation_2 and implement the method init().
Now as the parent class is Serialized,will the concrete subclasses
also be Serializable?How long does it take to write a demo?
import java.io.*;
abstract class Base implements Serializable {
public abstract void init();
class D1 extends Base {
public void init() {}
class D2 extends Base {
public void init() {}
public class SerializableExample {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Base obj1 = new D1();
Base obj2 = new D2();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(obj1);
out.writeObject(obj2);
out.flush();
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bais);
D1 d1 = (D1) in.readObject();
D2 d2 = (D2) in.readObject();
} -
Difference between multiple employment and concurrent employment
hi,
What is the difference between multiple employment and concurrent employment.
Regards,
ChandraHi
Multiple employment is one person working woth more than one company with different EE iD.
Person who has more than one personnel assignment with one enterprise or several affiliated enterprises in an cocurerent employee.
Please go thru the link.
http://help.sap.com/saphelp_47x200/helpdata/en/54/f535c614aa7a46800915c6f0dbc071/frameset.htm
Ravee
+91.99206.33669 -
How to create a thread safe and concurrent web part
Hi,
I am creating a sharepoint web part.
The web part will store the information in the sharepoint list.
The web part is going to be used by 300 users all at the same time at the same moment.
Each 300 users trying to update list clicking button on my web part almost every 20 seconds.
I am worried will the sharepoint List be able to handle so many concurrent updates.
How should I design my webpart so that such issues do not arise and my webpart is also fast.
Regards
VinodHi,
Per my understanding, there might be a concern about the performance and concurrent operation in your Visual Web Part.
By default, there is already a built-in system in SharePoint handling the concurrent operation in a list, if the workload is not so high, it would be OK for the commonly use in
your scenario.
If there would be a requirement about creating a “fast” web part,
a possible solution can be like this:
In the web part, users click button to submit the specific update requirements with some data to server. In server side, we can create an application to handle the requests(add/update/delete
item) from users sequentially one after one.
By doing this, in client side, the web part will only responsible for submitting user request with simple data, all the time consuming jobs will be split into small tasks and being
executed sequentially in server side.
Also, here are two links below about some useful tips in developing web part which would be helpful to you:
https://msdn.microsoft.com/en-us/library/dd583135%28v=office.11%29.aspx?f=255&MSPPError=-2147217396
http://apmblog.dynatrace.com/2010/03/18/how-to-avoid-the-top-5-sharepoint-performance-mistakes/
Thanks
Patrick Liang
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Dear Friends,
Please help me to find named number of users in PeopleSoft specific to module.Below are the modules i am using and i wanted to know named and concurrent users using these modules
Human Resources
Benefits Administration
Pension Administration
Thanks
Uday.Hi Bart,
Difference between named users and concurrent users:
Named user means when you buy BOXI you buy a certain amount of named user licenses and then you give each of these named users a login. It`s a cheaper type of license but you have to know exactly who your users are, and so is pretty useless if your userbase is constantly changing or your exposing Infoview over the web.
Concurrent user licenses are now only available in BOXI Edge - the equiv in BOXI Pro\Premium is a CPU license, which means you can let as many people login as your hardware will support. Concurrent user licenses are useful when you don`t know who your userbase is - you can just give a generic login for people to use. Or give people specific logins and not worry that they might not be using the system and using up a valuable named user license.
for more information follow the below links:
http://www.forumtopics.com/busobj/viewtopic.php?p=476977
http://www.forumtopics.com/busobj/printview.php?t=125096&start=0&sid=095882f7c0d636e7bca723e5930c21d3
Hope this helps.
Regards,
Deepti Bajpai -
Hi everyone:
I just want to know, say if you serialize an Object, obviously, the object will be stored in memory. But let us say if you deserialize it later on,
will the object be clean by the Garbage Collector?Your question suggests you might misunderstand the terms serialize and deserialize. You serialize an object to send it to another computer or store it out of memory, for example in a file. The serialized object can then be deserialized back into an in-memory object. Did you already know that, or does that help clear it up?
-
Serialize and Deserialize with Oracle 9 and Oracle 10
We have developed a client/server application. Client is a Java application and Server is written in C-Language; link between Java and C is RPC/JRPC.
We have to serialize and then deserialize a stream in a clob field in Oracle DB. When we deserialize with Oracle 9 we have no problem; now, after a migration to Oracle 10G, the deserialize failed at client level.
If we test in test environment (Oracle 9) with the same client and the same server we have no problem. The only difference between two enviroenment is only the version of Oracle (9 is OK - 10G is KO).
We use the OCI api.
The error message at client level is:
java.io.InvalidClassException: rpc.wDichiarazione; local class incompatible: stream classdesc serialVersionUID = 2960125282182152041, local class serialVersionUID = 2960125281578161001
Thanks of all
MarcoYou've changed a class definition. It has nothing to do with the Oracle version. Recompile that class with
private static long serialVersionUID = 2960125282182152041L;If you then get another exception, you need to evaluate the changes you've made to the class in the light of what it says about Versioning in the Serialization specification.
Maybe you are looking for
-
WM - chenge in block structure (increase in SUTs)
Hi gurus, i want to increase the Storage unit (stacks ,stacks hight). This customisation allows me to chenge the block structure. But gives an error while creating TO. 'block structure coincide with SUTS' Now i gone through diff documents & come to
-
Mail takes long time to arrive
Hello Experts, I am using 10.8 server for host my web sites and email. I created host name for for my server called mail.fm-host.biz and updated the pointed site from domain control pannel in domain reseller, and i see the it looks like working, my
-
Attach a File to a cell in the BW report...
Hi all, When I run a bw report on the web it is possible attach a text comment to a cell in the result table as a "document". This is an standard function but we need attach also a file in the same way. Please con you help me with this issue? Enrique
-
Link thumbnails in separate page to specific images in Easy Rotator?
Hello. I have a a web page with a grid of 16 thumbnail images. I have a separate web page running an Easy Rotator Slideshow. I want to be able to click on a thumbnail and have Easy Rotator start with it's corresponding image rather than from the star
-
Can I have two versions of Final Cut Pro installed on my Mac
It is posible to have Final Cut Pro 7 & FCP X installed on my Mac Pro.. currently I'm using FCP 7,