• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to check whether somebody's invoking a method?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I have a methodA that is being called several times per day by several threads. Inside methodA's method accesses a static variable STAT given by third party's API.
However, when time passes by, the STAT becomes 'buggy' and methodA returns null. What I want is that when methodA returns null, it will execute a methodB that will re-instantiate STAT. But before re-initializing STAT, it will first check whether methodA is still executing and will wait until methodA is not being invoked/running then it will re-instantiate STAT.

is this even possible in JAVA?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The general approach you described sounds very kludgy, frankly.  You should investigate why a static variable (emphasized as a hint) STAT becomes null as "time passes by".  Another hint: "time passing by" is NOT the cause of the STAT variable becoming "buggy".

Everything you described has the smell of a bug caused by improper or unsynchronized concurrent access to a global variable (emphasized as a hint).
 
Matt Taylor
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your response. However, I can't check it because I am just using that class provided by the third party api.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Taylor wrote:thanks for your response. However, I can't check it because I am just using that class provided by the third party api.



If the MethodA() that you are referring to, is part of a third party API, then my suggestion is to check the documentation for the third party API.  I agree with Junilu, that this is likely a thread issue, and this API is being used in a thread unsafe manner.

You need to figure out how you are using this API incorrectly, and well... use it correctly.

Henry  
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Taylor wrote:Hi guys, I have a methodA that is being called several times per day by several threads. Inside methodA's method accesses a static variable STAT given by third party's API.
However, when time passes by, the STAT becomes 'buggy' and methodA returns null. What I want is that when methodA returns null, it will execute a methodB that will re-instantiate STAT. But before re-initializing STAT, it will first check whether methodA is still executing and will wait until methodA is not being invoked/running then it will re-instantiate STAT.

is this even possible in JAVA?



Hi, Matt,

Synchronization issue on a variable that takes more than one word to set at the CPU?

Check out the java.util.concurrent package and/or the volatile keyword as appropriate.

With best regards,

Anton.
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic