Is there anything dangerous about using Thread.currentThread.sleep () in my main code?

in my code i use

Thread.currentThread().sleep(sleepTime);

in the main part (without the Thread object) of the code.

It seems to be working fine, but I'm worried there might be some kind of hidden trap that will later bite my ass.

Is there a better way to make your main process sit for a while? or is it a prescribed methodology?

EDIT:

In response to why I do this ...

I have a process that connects via HTTP or FTP to remote hosts and does things.

In other words...

material...

connect to remote ...

do things with a remote connection ...

close connection ...

more stuff ...

repeat if necessary.

, . , , . , .

, , ...

...

...

MAIN ( )

a) "done"

b) , , , .

, , MAX_WAIT_TIME. , .

, ( ), while, , .

, ... - . , , , , , . , , ?

+3
8

. , .

, .

+4

? , , GUI - , .

, , .

- :

Thread.sleep(sleepTime);

currentThread() , . .

, IDE - (, ).

+13

, 99 +% , , , . ?

+3

, Thread.sleep - , . ( , , ), .

+3

""? , , , .

no-args, connect (SocketAddress, int), ( ). , .

setSoTimeout() , , read() , , . , .

0

AFAIR Thread.sleep() , Object.wait(long timeout). Object.wait(long timeout). , , , Object.wait(long timeout) .

0

People often use a timer to execute pending events, but I prefer ScheduleExecutorService. You can use the same thread pool for all your timeout actions. (You may have a thread pool of size 1)

0
source

Source: https://habr.com/ru/post/1704689/


All Articles