You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by narges saleh <sn...@gmail.com> on 2020/04/06 16:23:56 UTC

Service Grid Requests

Hi All,

I understand that the ignite services are stateful. That being said, do I
need to synchronize the objects in my services or ignite queues the
requests to the same service, assuming that my services are deployed either
as node signleton or based on some affinity key?

thanks.

Re: Service Grid Requests

Posted by akorensh <al...@gmail.com>.
Hello,
   If you make a resource thread-safe, concurrent threads accessing this
resource will wait their turn.
   For example, if you have a HashMap in your singleton service and provide
a put (Key, Val) method as such:
   
   public *synchronized *void put(Object Key, Object Val) {
        return MyHashMap.put(Key, Val)
   }
  
   If several clients are accessing this service simultaneously, Ignite will
spin out a number of threads
   to service these clients. All these threads will call the put(..) methods
concurrently.
    
  Because you've *synchronized access to the put*(..) method, only one
thread will execute the method at a time. 

Thanks, Alex





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Service Grid Requests

Posted by narges saleh <sn...@gmail.com>.
Thanks for the reply.

If I make the resources thread safe, will the subsequent requests to the
service be queued or ignite spawns a new service, or load balances,
assuming that I deploy the service with node singleton or affinity option?

On Mon, Apr 6, 2020 at 2:28 PM akorensh <al...@gmail.com> wrote:

> Hi,
>
> If you structure your code such that each request is accessing a global
> resource that needs to be protected
>
> i.e. your service has a get(..) method which accesses a regular HashMap,
> then yes that HashMap needs to be protected.
>
> If you structured your service to use concurrent structures -- Ignite Maps,
> or concurrent HashMaps then you are ok.
>
> See this example:https://apacheignite.readme.io/docs/service-example
> Here all data is stored in Ignite Cache and therefore threadsafe.
> (If you were to replace the IgntieCache with a HashMap then the code in
> get/set would need to use locks/synchronized sections)
>
> Thanks, Alex
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Service Grid Requests

Posted by akorensh <al...@gmail.com>.
Hi,

If you structure your code such that each request is accessing a global
resource that needs to be protected

i.e. your service has a get(..) method which accesses a regular HashMap,
then yes that HashMap needs to be protected.

If you structured your service to use concurrent structures -- Ignite Maps,
or concurrent HashMaps then you are ok.

See this example:https://apacheignite.readme.io/docs/service-example
Here all data is stored in Ignite Cache and therefore threadsafe.
(If you were to replace the IgntieCache with a HashMap then the code in
get/set would need to use locks/synchronized sections)

Thanks, Alex



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/