Adding thread encapsulation (javalike)