• 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

Static Method call inside thread run

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a mutilthreaded application where I am calling a static method (with only local variables inside) which returns an int value in run method of thread.

I would like to know whether this call is thread safe, if it is so how it it functioning?

Thanks in Advance

-Ajay
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact that the method is static is of little importance here.

If the static method really does only use local variables, no object fields or methods, then it is thread-safe. If it accesses any object fields or methods, it may not be thread-safe, depending on what those fields or methods are used for, in other code.

If you can cut your code down to a manageable-sized extract, that is nevertheless complete enough for us to know what is going on, then please do post it here (in CODE tags). Then we'll be able to say for sure.
 
Cheenath Ajay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot,
I am pasting static method code below
<code>
public static byte[] addBytes(byte[] byteArray1, byte[] byteArray2) {

int finalByteLength = byteArray1.length + byteArray2.length;

byte[] finalByte = new byte[finalByteLength];

System.arraycopy(byteArray1, 0, finalByte, 0, byteArray1.length);

System.arraycopy(byteArray2, 0, finalByte, byteArray1.length, byteArray2.length);

return finalByte;
}
</code>
reply
    Bookmark Topic Watch Topic
  • New Topic