13th Mar 2021, 4:44 PM
Sufia Hashmi
Sufia Hashmi - avatar
7 Respostas
+ 1
Here some concept an coding mistakes: 1. You don't need create 2 classes that extends Thread. Only instances of that if do the same work. 2. The constructor name must be the same text as the class. In Thread1 you tip Thread as name. 3. Take care to assign same name in constructor if you want to set value of an object attribute (remember use this.xxxx = xxxx) 4. its a bad practice autostart a thread inside it constructor. 5. Java is case sensitive. In Thread2 constructor you write Start() instead start(), print instead Print to declare type of vars.... https://code.sololearn.com/cn9mN7Eo3CMe/?ref=app
13th Mar 2021, 5:05 PM
David OrdĂĄs
David OrdĂĄs - avatar
+ 1
It's Me Then you need declare an attribute AtomicInteger inside Print class to use as counter holder between thread calls, and use current value as factor to operate with for-i counter because your loop only goes from one to four note you al have.... "i < 5". It must be "i <= 5" to count from 1 to 5 inclusive. https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/concurrent/atomic/AtomicInteger.html E.g.: final AtomicInteger counter = new AtomicInteger(0); for (int i = 1; i <= 5; i++) print (threadname, i + counter.getAndAdd(1))
13th Mar 2021, 5:17 PM
David OrdĂĄs
David OrdĂĄs - avatar
+ 1
It's Me code updated đŸ˜„đŸ˜„đŸ˜‰đŸ˜‰đŸ˜‰ https://code.sololearn.com/cn9mN7Eo3CMe/?ref=app Nice challenge for my memory. If you have any question... here I am đŸ€—đŸ€—đŸ€“ If this solve your problem remember mark as solved checking one of my answers
13th Mar 2021, 6:28 PM
David OrdĂĄs
David OrdĂĄs - avatar
0
Mistake of.... What is supposed have to do the program?
13th Mar 2021, 4:51 PM
David OrdĂĄs
David OrdĂĄs - avatar
0
David OrdĂĄs đŸ‡Ș🇾 output should b Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 11 Thread 12 Thread 13 Thread 14 Thread 15
13th Mar 2021, 4:54 PM
Sufia Hashmi
Sufia Hashmi - avatar
0
David OrdĂĄs đŸ‡Ș🇾 dear I need ThDavid OrdĂĄs đŸ‡Ș🇾 output should b Thread 1 Thread 2 Thread 3 Thread 4 Thread 5 Thread 11 Thread 12 Thread 13 Thread 14 Thread 15
13th Mar 2021, 5:15 PM
Sufia Hashmi
Sufia Hashmi - avatar
13th Mar 2021, 5:32 PM
Sufia Hashmi
Sufia Hashmi - avatar