Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Static Method call inside thread run  RSS feed

 
Cheenath Ajay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • 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
  • 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>
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!