optimize threading method