Write a program called ReverseHello.java that creates a thread (let's call it
Thread 1). Thread 1 creates another thread (Thread 2); Thread 2 creates
Thread 3; and so on, up to Thread 50. Each thread should print "Hello from
Thread <num>!", but you should structure your program such that the
threads print their greetings in reverse order.
class reversehello(Thread):
def run(self):
for j in range(49, 0, -1):
print("Hello from Thread <"+(j+1)+">")
try:
Thread.sleep(1000)
except Exception as e:
print(e)
@staticmethod
def main():
t = [None for _ in range(50)]
for i in range(0, 49):
t[i] = reversehello()
for i in range(49, 0, -1):
t[i].start()
Comments
Leave a comment