You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Igor Clark <ig...@pokelondon.com> on 2008/04/10 17:57:34 UTC
Singletons, data access and safety in Mina
Hi there,
I'm thinking about using Mina for an application which will give
clients read/write access to a single data structure containing a map
of objects which change over time. The clients will need to be able to
say "give me list of objects at location X", "put object X at location
Y", etc.
The very basic idea is to have a singleton map object with which
clients communicate. Obviously the data this object managed needs not
to be corrupted, deadlocked or stuck in race conditions. In a threaded
version, I'd start to think about synchronization, but I'm not sure of
the correct approach using Mina.
Does anybody have any pointers, or Is there some documentation as to
how to manage the concurrent access to this structure within Mina? Or
perhaps suggestions for better ways to do it in this context?
Many thanks,
Igor
Re: Singletons, data access and safety in Mina
Posted by Igor Clark <ig...@pokelondon.com>.
Thanks Trustin!
Bests
Igor
On 12 Apr 2008, at 04:50, "이희승 (Trustin Lee) <tr...@gmail.com>
wrote:
> Hi Igor,
>
> As you already noticed, ConcurrentHashMap would work for you IMHO.
> And
> I don't think you need to manage another thread pool or something
> similar for solving concurrent access problem.
>
> HTH,
>
> Igor Clark wrote:
>> Thanks very much Mark!
>>
>> I'm reasonably happy about safeguarding concurrent access in a
>> threaded
>> environment, but the last time I did anything like that in Java was
>> before 1.5, so I don't know the java.util.concurrency package; I'll
>> look
>> into it, particularly the Concurrent* classes. Thanks.
>>
>> However this all seems to emphasise an area in which my
>> understanding is
>> lacking. A lot of the stuff I've read about java.util.concurrent -
>> and
>> the description of that book - talk a fair amount about thread
>> concurrency.
>>
>> Are you saying that I need to implement what I'm talking about using
>> threads, even within Mina? I thought the point of frameworks like
>> Mina
>> was to avoid scaling with threads. Am I missing something?
>>
>> Thanks,
>> Igor
>>
>> On 11 Apr 2008, at 13:41, Mark Webb wrote:
>>
>>> I would suggest you take full advantage of the
>>> java.util.concurrency data
>>> structures and if you have not done so already, pick up a copy of
>>> "Java
>>> Concurrency in Practice". Its a fantastic book.
>>>
>>> http://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1207917684&sr=8-1
>>>
>>>
>>> On Thu, Apr 10, 2008 at 11:57 AM, Igor Clark <ig...@pokelondon.com>
>>> wrote:
>>>
>>>> Hi there,
>>>>
>>>> I'm thinking about using Mina for an application which will give
>>>> clients
>>>> read/write access to a single data structure containing a map of
>>>> objects
>>>> which change over time. The clients will need to be able to say
>>>> "give me
>>>> list of objects at location X", "put object X at location Y", etc.
>>>>
>>>> The very basic idea is to have a singleton map object with which
>>>> clients
>>>> communicate. Obviously the data this object managed needs not to be
>>>> corrupted, deadlocked or stuck in race conditions. In a threaded
>>>> version,
>>>> I'd start to think about synchronization, but I'm not sure of the
>>>> correct
>>>> approach using Mina.
>>>>
>>>> Does anybody have any pointers, or Is there some documentation as
>>>> to how
>>>> to manage the concurrent access to this structure within Mina? Or
>>>> perhaps
>>>> suggestions for better ways to do it in this context?
>>>>
>>>> Many thanks,
>>>> Igor
Re: Singletons, data access and safety in Mina
Posted by 이희승 (Trustin Lee) <t...@gmail.com>.
Hi Igor,
As you already noticed, ConcurrentHashMap would work for you IMHO. And
I don't think you need to manage another thread pool or something
similar for solving concurrent access problem.
HTH,
Igor Clark wrote:
> Thanks very much Mark!
>
> I'm reasonably happy about safeguarding concurrent access in a threaded
> environment, but the last time I did anything like that in Java was
> before 1.5, so I don't know the java.util.concurrency package; I'll look
> into it, particularly the Concurrent* classes. Thanks.
>
> However this all seems to emphasise an area in which my understanding is
> lacking. A lot of the stuff I've read about java.util.concurrent - and
> the description of that book - talk a fair amount about thread concurrency.
>
> Are you saying that I need to implement what I'm talking about using
> threads, even within Mina? I thought the point of frameworks like Mina
> was to avoid scaling with threads. Am I missing something?
>
> Thanks,
> Igor
>
> On 11 Apr 2008, at 13:41, Mark Webb wrote:
>
>> I would suggest you take full advantage of the java.util.concurrency data
>> structures and if you have not done so already, pick up a copy of "Java
>> Concurrency in Practice". Its a fantastic book.
>>
>> http://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1207917684&sr=8-1
>>
>>
>> On Thu, Apr 10, 2008 at 11:57 AM, Igor Clark <ig...@pokelondon.com> wrote:
>>
>>> Hi there,
>>>
>>> I'm thinking about using Mina for an application which will give clients
>>> read/write access to a single data structure containing a map of objects
>>> which change over time. The clients will need to be able to say "give me
>>> list of objects at location X", "put object X at location Y", etc.
>>>
>>> The very basic idea is to have a singleton map object with which clients
>>> communicate. Obviously the data this object managed needs not to be
>>> corrupted, deadlocked or stuck in race conditions. In a threaded
>>> version,
>>> I'd start to think about synchronization, but I'm not sure of the
>>> correct
>>> approach using Mina.
>>>
>>> Does anybody have any pointers, or Is there some documentation as to how
>>> to manage the concurrent access to this structure within Mina? Or
>>> perhaps
>>> suggestions for better ways to do it in this context?
>>>
>>> Many thanks,
>>> Igor
>>>
>>
>>
>>
>> --
>> --------------------------------
>> Talent hits a target no one else can hit; Genius hits a target no one
>> else
>> can see.
>
> --
> Igor Clark • POKE • 10 Redchurch Street • E2 7DD • +44 (0)20 7749 5355 •
> www.pokelondon.com
>
>
>
--
Trustin Lee - Principal Software Engineer, JBoss, Red Hat
--
what we call human nature is actually human habit
--
http://gleamynode.net/
Re: Singletons, data access and safety in Mina
Posted by Igor Clark <ig...@pokelondon.com>.
Thanks very much Mark!
I'm reasonably happy about safeguarding concurrent access in a
threaded environment, but the last time I did anything like that in
Java was before 1.5, so I don't know the java.util.concurrency
package; I'll look into it, particularly the Concurrent* classes.
Thanks.
However this all seems to emphasise an area in which my understanding
is lacking. A lot of the stuff I've read about java.util.concurrent -
and the description of that book - talk a fair amount about thread
concurrency.
Are you saying that I need to implement what I'm talking about using
threads, even within Mina? I thought the point of frameworks like Mina
was to avoid scaling with threads. Am I missing something?
Thanks,
Igor
On 11 Apr 2008, at 13:41, Mark Webb wrote:
> I would suggest you take full advantage of the java.util.concurrency
> data
> structures and if you have not done so already, pick up a copy of
> "Java
> Concurrency in Practice". Its a fantastic book.
>
> http://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1207917684&sr=8-1
>
> On Thu, Apr 10, 2008 at 11:57 AM, Igor Clark <ig...@pokelondon.com>
> wrote:
>
>> Hi there,
>>
>> I'm thinking about using Mina for an application which will give
>> clients
>> read/write access to a single data structure containing a map of
>> objects
>> which change over time. The clients will need to be able to say
>> "give me
>> list of objects at location X", "put object X at location Y", etc.
>>
>> The very basic idea is to have a singleton map object with which
>> clients
>> communicate. Obviously the data this object managed needs not to be
>> corrupted, deadlocked or stuck in race conditions. In a threaded
>> version,
>> I'd start to think about synchronization, but I'm not sure of the
>> correct
>> approach using Mina.
>>
>> Does anybody have any pointers, or Is there some documentation as
>> to how
>> to manage the concurrent access to this structure within Mina? Or
>> perhaps
>> suggestions for better ways to do it in this context?
>>
>> Many thanks,
>> Igor
>>
>
>
>
> --
> --------------------------------
> Talent hits a target no one else can hit; Genius hits a target no
> one else
> can see.
--
Igor Clark • POKE • 10 Redchurch Street • E2 7DD • +44 (0)20 7749 5355
• www.pokelondon.com
Re: Singletons, data access and safety in Mina
Posted by Mark Webb <el...@gmail.com>.
I would suggest you take full advantage of the java.util.concurrency data
structures and if you have not done so already, pick up a copy of "Java
Concurrency in Practice". Its a fantastic book.
http://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1207917684&sr=8-1
On Thu, Apr 10, 2008 at 11:57 AM, Igor Clark <ig...@pokelondon.com> wrote:
> Hi there,
>
> I'm thinking about using Mina for an application which will give clients
> read/write access to a single data structure containing a map of objects
> which change over time. The clients will need to be able to say "give me
> list of objects at location X", "put object X at location Y", etc.
>
> The very basic idea is to have a singleton map object with which clients
> communicate. Obviously the data this object managed needs not to be
> corrupted, deadlocked or stuck in race conditions. In a threaded version,
> I'd start to think about synchronization, but I'm not sure of the correct
> approach using Mina.
>
> Does anybody have any pointers, or Is there some documentation as to how
> to manage the concurrent access to this structure within Mina? Or perhaps
> suggestions for better ways to do it in this context?
>
> Many thanks,
> Igor
>
--
--------------------------------
Talent hits a target no one else can hit; Genius hits a target no one else
can see.