Main thread and child threads

classic Classic list List threaded Threaded
5 messages Options
namluc.tran@euranova.eu namluc.tran@euranova.eu
Reply | Threaded
Open this post in threaded view
|

Main thread and child threads

Hello Everyone,

I would like to achieve the following system: a main thread creates and initializes an Ignite data grid. Multiple child threads are created and each have to access the grid created on the main thread. In order to achieve this I thought of the following:
- An ignite grid is created on the main thread with parametrized cache configurations
- The child threads initialize the same cache grid configurations but in client mode (setClientMode(true)).


My questions are:

1/ Is this the right way of achieving the desired behaviour using Ignite?
2/ The child thread might be stopped without going though a cleanup method. Doing this will leave the client grid running and the process won't terminate. Is there a way to close the grid started on the child threads from the main thread, or a way to systematically close all the running grids?

Thank you and best regards,

Tran Nam-Luc

Ognen Duzlevski Ognen Duzlevski
Reply | Threaded
Open this post in threaded view
|

Re: Main thread and child threads

I have an Akka actor system where a set of partitioned caches is created in the "main thread" and these caches are used in actors for various purposes. The close() method on a cache is currently implemented to destroy a cache and its contents but there is a separate destroyCache() method if you want to achieve that. You can use getOrCreateCache() method to create a cache if it doesn't exist or get it if it does - the setClientMode() thing is separate. I create my grid cluster by running ignite.sh with an xml config file on each machine - regardless of whether there is a cache client running or not - the grid is permanent this way.

On Wed, Jun 17, 2015 at 10:53 AM, Nam-Luc Tran <[hidden email]> wrote:
Hello Everyone,

I would like to achieve the following system: a main thread creates and initializes an Ignite data grid. Multiple child threads are created and each have to access the grid created on the main thread. In order to achieve this I thought of the following:
- An ignite grid is created on the main thread with parametrized cache configurations
- The child threads initialize the same cache grid configurations but in client mode (setClientMode(true)).


My questions are:

1/ Is this the right way of achieving the desired behaviour using Ignite?
2/ The child thread might be stopped without going though a cleanup method. Doing this will leave the client grid running and the process won't terminate. Is there a way to close the grid started on the child threads from the main thread, or a way to systematically close all the running grids?

Thank you and best regards,

Tran Nam-Luc


vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Main thread and child threads

In reply to this post by namluc.tran@euranova.eu
Tran,

Are you talking about different threads within one process? If so, you can simply start one Ignite instance and use it in all child threads. All Ignite APIs (Ignite, IgniteCache, etc.) are thread-safe and designed to be accessed from multiple threads in parallel.

-Val
namluc.tran@euranova.eu namluc.tran@euranova.eu
Reply | Threaded
Open this post in threaded view
|

Re: Main thread and child threads

In reply to this post by namluc.tran@euranova.eu

Val,

This is not necessarily the case, in the way the threads are created in our system there is actually no way of passing the Ignite instance as parameter to the threads. Is there a way to create an Ignite instance on the main thread and retrieve that same instance back on the child threads?

Thanks and best regards,

Tran Nam-Luc


At Thursday, 18/06/2015 on 1:42 vkulichenko wrote:
Tran,

Are you talking about different threads within one process? If so, you can
simply start one Ignite instance and use it in all child threads. All Ignite
APIs (Ignite, IgniteCache, etc.) are thread-safe and designed to be accessed
from multiple threads in parallel.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Main-thread-and-child-threads-tp516p527.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Main thread and child threads

namluc.tran@euranova.eu wrote
Is there a way to create an Ignite
instance on the main thread and retrieve that same instance back on
the child threads?
Yes, you can use Ignition.ignite() method.

-Val