What's new

Closed what thread am i blocking?

Status
Not open for further replies.

fireclouu

Honorary Poster
Joined
Jun 1, 2014
Posts
438
Solutions
1
Reaction
152
Points
189
nalilito talaga ako rito haha. lets say i have this class
SomeClass.java

Java:
public class SomeClass {
    public boolean looping = true;
   
    public void loop() {
        while (looping) {
            // some code
   
        }
    }
}

and my Main.java
Java:
public class Main {
SomeClass someClass;
public static void main(String args[]) {
someClass = new SomeClass();

new Thread() {
@Override
public void run() {
someClass.loop();
}
}.start();
}

on what thread i am blocking? sa bagong thread o sa main?
 
Ano po? Paki ayos po question.

sorry , i mean tungkol po 'to sa thread, kung saan magkakaroon ng effect yung loop, kasi ininstantiate ko siya sa Main , then gumawa ng new thread sa main saka tinawag yung loop method sa loob ng SomeClass, dito ako nalilito kung anong thread ang blocked, both threads, main thread or yung new thread?
 
There is no blocked thread here. Main thread is running while another thread is running/executing the loop from your SomeClass Class. This is observable when you simulate threads in Android studio where threads are beneficial when your program has heavy task on background without interfering the Main thread that's handling the main processes and UI tasks.
 
There is no blocked thread here. Main thread is running while another thread is running/executing the loop from your SomeClass Class. This is observable when you simulate threads in Android studio where threads are beneficial when your program has heavy task on background without interfering the Main thread that's handling the main processes and UI tasks.

thanks aa1012 :) mali pala question ko pero nasagot mo yung "main thread-new thread" problem ko. api specific pala problem ko sa MediaPlayer library , dapat pala ayun sinabi ko una pa lang haha.
 
Ano ba dinidevelop mo paps?
medyo tapos na kaso messy code base ko haha, 8080 emulation , specifically space invaders, nagpalit na ko ng library ko from MediaPlayer to SoundPool , di ko makuha async niya haha , ang hirap na kasi imaintain pag lumalaki
 
medyo tapos na kaso messy code base ko haha, 8080 emulation , specifically space invaders, nagpalit na ko ng library ko from MediaPlayer to SoundPool , di ko makuha async niya haha , ang hirap na kasi imaintain pag lumalaki

Android based paps? ganda ng project mo. That's fine kung mejo messy, ako nga din bago lang sa Android dev e. yung gawa kong messaging app with Bluetooth based peer messaging ang messy ng codes kahit gumamit ako ng 3 tier based classes, abstract at interfaces. Mahirap talaga pag di ka familiar sa isang sdk, library at api, mangangapa ka pero kaya naman imanipulate at paglaruan. masayang pag aralan.
 
kaylangan mo talaga ng async sa ganyang mga apps kasi maraming backgroud tasks yan na kaylangan ng threads at jobscheduler at services.
 
Android based paps? ganda ng project mo. That's fine kung mejo messy, ako nga din bago lang sa Android dev e. yung gawa kong messaging app with Bluetooth based peer messaging ang messy ng codes kahit gumamit ako ng 3 tier based classes, abstract at interfaces. Mahirap talaga pag di ka familiar sa isang sdk, library at api, mangangapa ka pero kaya naman imanipulate at paglaruan. masayang pag aralan.

agree. pagkatapos magdusa sa syntax ni java, mas madugo libraries haha :)
 
Status
Not open for further replies.

Similar threads

Back
Top