• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Access main thread variable values in callback method

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am calling Rest API using AsyncRestTemplate inside a loop. Once callback returns i need to access main thread values. But the issue is i am calling AsyncRestTemplate inside a loop as below .




inside callback i need t oaccess list values. but issue is since this runs  inside a loop when callback comes loop may in a different iteration. So how can i access the same values when i am calling exchange methos ?
 
Marshal
Posts: 27531
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't said what's preventing you from using the variables in question, or even what those variables are, but in the absence of that I will just suggest that you declare the variables to be final.

If that isn't the answer you want, then go ahead and post more details.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually i need to get the value from each callback. for example i have a list which contain 10 items. So that means there will be 10 call backs. So each call back i need to access the list and get relevant  value. For example for the 1st iteration  i need to get 1st value of list, but when callback comes the i value of iteration may changed to different value. So how do i know 1st iteration callback comes which items to get from the list?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic