Work light: making a call to the static java method and creating an object

Do I need suggestions or am I doing a custom java method as a static OR access through a Java object from the adapter?

My scenario: thousands of users commit transactions, and each user again and again accesses the same method and simply changes some values ​​specific to that user or transaction.

Now, if I create them as static methods, this will cause problems for users, since we know that calling the adapter is asynchronous .... so if several users calling the same method at the same time, then it will cause a problem, it returns different meanings to each other?

Or, if I access all user java methods, first declaring this class object, and then accessing the methods, providing the parameters .... so that when multiple users access the same method at the same time, then they will get proper / relevant data?

In terms of performance, which approach is good and uses the static method method, it brings users incorrect data ... one user information to another, and the other to another person.

thanks Abdul Ahad

------------ my code is similar to ---

java code: public static String getBalanceSummaries(String userAct){ String replyMsg=""; try { replyMsg = getBalanceStatementfromMQ(userAct); }catch(Exception e) {} return replyMsg; } -----WL Adapter code:------ function showAllBalace(userActNo){ return{ result: com.my.package.getBalanceSummaries(userActNo) }; } 
+4
source share
1 answer

I believe that you confuse static methods with static fields. Static methods are simply code that is not associated with any particular instance of an object. In principle, any method that does not use this or super references can be a candidate for static, provided that they do not override another method and are not intended to be overridden. Static methods have no additional wrt multithreading problems compared to conventional methods.

Static fields, on the other hand, are by definition common to all threads, and access to them must be protected as with any shared resource. Any method using a static field, whether this method is static or not, should be checked for concurrency problems.

As far as performance is concerned, there is compelling evidence that static methods can provide better performance than conventional virtual methods, but to be honest, I wouldn't worry about that until the profiler tells me. Premature optimization is the root of all evil ...

+2
source

All Articles