Re: [Simple-support] What does the Thread-safety guarantee of Persister mean?
Brought to you by:
niallg
|
From: Kiran R. <tec...@gm...> - 2013-01-03 07:13:28
|
Great! Thanks for the clarification.
On Thu, Jan 3, 2013 at 12:16 PM, Niall Gallagher - Yieldbroker <
Nia...@yi...> wrote:
> Yes, it will work in this scenario****
>
> ** **
>
> *From:* Kiran Rao [mailto:tec...@gm...]
> *Sent:* Thursday, 3 January 2013 5:19 PM
> *To:* simple-support
> *Subject:* [Simple-support] What does the Thread-safety guarantee of
> Persister mean?****
>
> ** **
>
> The docs for Persister have this to say:****
>
> It is fully thread safe and can be shared by multiple threads without
> concerns****
>
>
> What does this mean? If multiple threads share an instance of Persister,
> and
> read operations are interleaved with write operations, will Persisterstill "do
> the right thing"?
>
> To illustrate, consider the following code:
>
> public class LogicClass{
>
> private final Serializer serializer = new Persister();
>
> public User parse(String aString){
> return serializer.read(User.class, aString);
> //Exception handling ommitted for brevity.
> }
>
> public String frame(Account account){
> StringWriter writer = new StringWriter();
> serializer.write(account, writer);
> //Exception handling ommitted for brevity.
> return writer.toString();
> }
> }
>
> Imagine LogicClass is a singleton (with lower-case 's') shared by
> multiple
> threads. Now it is possible that one thread is parsing User at the same
> time that
> another is serializing Account. Since LogicClass is a singleton, there
> is also
> only a single instance of Persister.
>
> How is Persister intended to behave in such circumstances?
> ****
>
>
> --
> Regards,
> =======
> Kiran Rao
> http://curioustechizen.blogspot.com/
> http://stackoverflow.com/users/570930/curioustechizen****
>
--
Regards,
=======
Kiran Rao
http://curioustechizen.blogspot.com/
http://stackoverflow.com/users/570930/curioustechizen
|