Hi,

Please check if making cache field final will help you. There could be a
problem with inter-thread visibility.
Try changing the field signature to "private *final* IgniteCache<String,
InputFields> cache;"

Kind regards,
Alex.

On Thu, Jun 22, 2017 at 1:10 AM, mdolgonos [via Apache Ignite Users] <
[email protected]> wrote:

> I have the singleton service class that creates an Ignite cache and
> provides a public method to add entries to the cache. Below is the code
> that creates cache:
>
> @Service("cacheService")
> @Scope(value = "singleton")
> public class RentdCacheService {
>         private IgniteCache<String, InputFields> cache = null;
>         public RentdCacheService() {
>                 super();
>                 createCache();
>         }
>
>         private void createCache() {
>                 try {
>                         Ignition.setClientMode(true);
>                         Ignite ignite = Ignition.start("default-config.xml");
>
>                         cache = ignite.getOrCreateCache("myCacheName");
>                         System.out.println("Created Ignite cache: " +
> cache);
>                 } catch (Exception ex) {
>                         ex.printStackTrace();
>                 }
>         }
>
> //The following method adds to the cache:
>
>         public void addRowToCache(String key, InputFields dataRow) {
>                 System.out.println("adding key="+key + " and
> dataRow="+dataRow);
>                 System.out.println("cache: " + cache);
>                 cache.put(key, dataRow);
>         }
> }
>
> In the system output I can see that the cache was created ( or received
> from the grid if created earlier). However, when the addRowToCache method
> is called the cache is null. I'm using a slightly modified
> default-config.xml where I added the grid name property and a discoverySpi
> property.
> can someone please help me understand why the cache gets dereferenced.
> Thank you.
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-ignite-users.70518.x6.nabble.com/Ignite-
> cache-received-by-the-client-becomes-null-tp14036.html
> To start a new topic under Apache Ignite Users, email
> [email protected]
> To unsubscribe from Apache Ignite Users, click here
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1&code=YWxleGFuZGVyLmZlZG90b2ZmQGdtYWlsLmNvbXwxfC0xMzYxNTU0NTg=>
> .
> NAML
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/Ignite-cache-received-by-the-client-becomes-null-tp14036p14042.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to