I want to use some mutable vars defined in a thread MyT which extends Java's Thread
in application and the usage will be as Thread.currentThread.asInstanceof[MyT]
to reference and update mutable vars in it.
Will this be thread-safe?
update
I wrote some application using scala without any consideration of multi-thread issues and with the so-called worst practice of using mutable variables in object (because it is so easy to use for beginners!).
But now somehow the project extends to a web application, that I have to deal with multi-threading issues.
I dont have time to rewrite the code again, to refactor every mutable vars in object as arguments around (probably one solution of not using global object mutable vars), so I am thinking about moving the mutable vars in object to a thread class that extends Thread
class, and refactor the code to use Thread.currentThread
and then cast the instance to my extends thread type, and then to reference/update to the mutable vars which are originally global mutable vars.
So here comes my original question.