ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Java code with callbacks leaving phantom threads

Post new topic  Reply to topic
 Java code with callbacks leaving phantom threads « View previous topic :: View next topic » 
Author Message
urufberg
PostPosted: Mon Mar 26, 2018 7:29 am    Post subject: Java code with callbacks leaving phantom threads Reply with quote

Apprentice

Joined: 08 Sep 2017
Posts: 28

Hello,

I was wondering if anyone has any experience dealing with a java code that leaves a thread open for callbacks. I have ran in several problems with this and I've got weir behavior on the node.
Mainly I was able to "fix" them all but I have 2 problems I cannot solve:

1) When deploying an application with this java code, no matter if the flow that contains it is stopped or started, the code runs (weird right?)

2) Another thing I've detected is that when I switched the environment (from a development environment to a staging one) where the app was reading the message and re-deployed, the app started reading from both (the old one and the new one). Once I restart the Integration Node, the expected behavior kicks in only reading from the staging environment.

This is why I'm very inclined to think that the java code is leaving a 'phantom thread' somwhere on the bus.

Any ideas/comments/experience would be appreciated.

For some context:
- Im running on IIB 10 Fixpack 11
- MQ Version 9
- The java code is used to call a method in an SDK (from a 3rd party app) that brings JSON files and writes them down.

It's a %100 confirmed that it's not the SDK working wrong, the company which we are working with has used the same SDK not for hundred but thousands of organizations in the region.

Regards,
Francisco.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Mar 26, 2018 8:00 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Well Paco, as you've seen with the errors you've already fixed, it's most probably your design, your code or a mixture of both.

But as you have revealed none, we won't be able to help.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
urufberg
PostPosted: Mon Mar 26, 2018 8:10 pm    Post subject: Reply with quote

Apprentice

Joined: 08 Sep 2017
Posts: 28

The thing is, it's not my code. It's a documented code of this application on how to do the callback (literally one method) and writing what I get down in a Json file.

About the design, it's just a timeoutNotification node that triggers the Java (if, for some reason the callback fails).

I solved two problems, one of it was that when deploying the app
the whole node went down and the other had something to do with the fact that I can't proceed with the flow from that JavaCompute because it would try to form more messages than one.

I was wondering If anyone has runned into this kind of problem, because as I said, a lot of testing is showing a weird behavior of the Bus. I know that not sharing the code perhaps minimizes the help that anyone could give me, but sadly I can't do it.

Thank you in advance,
Regards
Francisco
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Mar 26, 2018 8:14 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

I wasn't saying its the call back in itself. I suspect it is in how the flow is doing the callback.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
abhi_thri
PostPosted: Mon Mar 26, 2018 11:10 pm    Post subject: Reply with quote

Knight

Joined: 17 Jul 2017
Posts: 516
Location: UK

Hi...regarding
Quote:
1) When deploying an application with this java code, no matter if the flow that contains it is stopped or started, the code runs (weird right?)


are you using javacompute's onInitialize method at all, that gets executed on deployment itself which might explain the behavior (depending on what is coded in that method)
Back to top
View user's profile Send private message
urufberg
PostPosted: Tue Mar 27, 2018 8:34 am    Post subject: Reply with quote

Apprentice

Joined: 08 Sep 2017
Posts: 28

Hi, finally I'm able to share the code:

Code:

protected static String clientId = null;
   protected static String clientSecret = null;
   protected static String ambiente = null;
   protected static String filePath = null;

   public void onInitialize() throws MbException {
      try {
                  
         // User-defined properties
         clientId = (String) getUserDefinedAttribute("ClientId");
         clientSecret = (String) getUserDefinedAttribute("ClientSecret");
         ambiente = (String) getUserDefinedAttribute("Ambiente");
         filePath = (String) getUserDefinedAttribute("FilePath");
         
      } catch (Exception e) {
         // This exception will cause the deploy of this Java compute node to
         // fail
         // Typical cause is the JAXB package above is not available
         throw new MbUserException(this, "onInitialize()", "", "",
               e.toString(), null);
      }
   }

   public void evaluate(MbMessageAssembly contact admin) throws MbException {
      
      
      try {

         // Crear credenciales

         Credentials credentials = new Credentials();
         credentials.setClientId(clientId);
         credentials.setClientSecret(clientSecret);
         
         /*
          * 0 - DEVELOPMENT
          * 1 - STAGING
          * 2 - PRODUCTION
          */
         
         if ( ambiente.equals("0") ) {
            credentials.setEnvironment(Environments.DEVELOPMENT);
         } else if ( ambiente.equals("1") ) {
            credentials.setEnvironment(Environments.STAGING);
         } else if ( ambiente.equals("2") ) {
            credentials.setEnvironment(Environments.PRODUCTION);
         } else {
            credentials.setEnvironment(Environments.DEVELOPMENT);
         }

         // Acceso con apiClient

         ApiClient apiClient = new ApiClient(credentials);
         apiClient.getOrdersClient().getAll(

         //Callback Java method
               
         new OnReceivedOrder() {

            public boolean call(Order order) {
               
               System.out.println("Orden " + order.getId() + " recibida");
               
               try {
                  
                  // Guardado en archivo, cada orden es un archivo
                  
                  List<String> lines = new ArrayList<String>(0);
                  lines.add("{\"order\":" + order.toString() + "}");
                  Path file = Paths.get( filePath + "order" + order.getId() );
                  Files.write(file, lines, Charset.forName("UTF-8"));
                  
                  
                  
               } catch (IOException e) {
                  System.out.println("ERROR ConsultarPedidos " + e.getMessage() );
               }
               
               return true;
            }

         }, new OnError() {

            @Override
            public void call(ApiException ex) {

               // Something went wrong
               System.out.println("Error " + ex.getMessage());

            }

         });

         //System.out.println("Ejecuci�n de ConsultarPedidosTY - ");
      } catch (Exception e) {
         // Example Exception handling
         throw new MbUserException(this, "evaluate()", "", "", e.toString(),
               null);
      }

}


Hope it helps!
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Mar 28, 2018 7:49 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Terrible design writing directly to the file system.
For each order you should write to the tree and propagate. You can then persist the message using an MQOutput or a FileOutput node...

My guess is your phantom threads are resources that have not been correctly flushed and closed... and that you may well have a resource leakage.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
urufberg
PostPosted: Wed Mar 28, 2018 8:27 pm    Post subject: Reply with quote

Apprentice

Joined: 08 Sep 2017
Posts: 28

Thank you for yor reply... As stated before, it's not a normal flow. I already tried to write to the tree and propagate, then persist it but as I mentioned this method has callbacks. Then when I propagate and leave the node, the thread of that method remains open and when a new order arrives and tries to propagate there is no environment at all (causing memory leaks and other ugly stuff). Same thing happens when the flow is down. That is why the team took the decision to write it down on the file system and then take the order in an other flow with a File Input Method.

About this:
Quote:
My guess is your phantom threads are resources that have not been correctly flushed and closed...

No other resources used than what you see in the java compute. As stated before, this SDK call it's used by a lot of small-middle companies on the region and they don't have this problem (ofc non of them implemented with IIB but with a javaApp).

As I said, I was wondering if anyone had any experience dealing with a method with callbacks remaining open that could give me some insight on this kind of problems. Also if you have some ideas to improve the code, go for it. I'm open to new ideas!

Thanks in advance,
Regards,
Francisco
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Java code with callbacks leaving phantom threads
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.