FAQ Database Discussion Community


What will happen use run() instead of start() of a thread? [duplicate]

java,multithreading,java-threads
This question already has an answer here: When would you call java's thread.run() instead of thread.start()? 14 answers Fallowing thread class is working fine. I can understand its process. Then I changed mc.srart() into mc.run() but nothing changed and there was no any errors. Can someone please explain this...

Scenario's where a Java thread running in infinite loop for a long run be terminated by JVM

java,tomcat,jvm,java-threads
I have a Runnable thread which loops through an infinite loop. Per iteration it sleeps upto next task time and then does some task. This task is very critical hence makes the thread running it also very critical. I am not really a java thread expert so I was wondering...

Some concurrency-design in java

java,multithreading,concurrency,runnable,java-threads
I need to retrieve a huge picture from a server but the server can't do that because the image is too big. I can give "coordinates" so that I can retrieve small parts of that picture. So I split the picture in to 100 tiles and than append 10 tiles...

Don't understand output order of thread constructor, start and run methods

java,multithreading,java-threads
Why does this code always print this? in start oops in ctor oops And doesn't call the run method even though the thread already has been started. when thread started firstly start method called then run. class MyThread extends Thread { public MyThread(String name) { this.setName(name); start(); System.out.println("in ctor "...

What exactly does the call to the SwingUtilities.invokeLater() method into the main class that perform a Swing application?

java,swing,user-interface,swingutilities,java-threads
I am pretty new in Swing and I have the following doubt about this main class that start a Swing application founded on an tutorial project: package com.caveofprogramming.designpatterns.demo1; import javax.swing.SwingUtilities; import com.caveofprogramming.designpatterns.demo1.controller.Controller; import com.caveofprogramming.designpatterns.demo1.model.Model; import com.caveofprogramming.designpatterns.demo1.view.View; public class Application { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override...

java multi threading - how to synchronise

java,java-threads
I have a class with following method public class Test { private List l1; public void send() { for (<type> x : l1) { //send to receivers and put a log in DB } } } This Test class is used by different threads which will fill the variable 'l1'...

How to stop a currently executing command

android,android-logcat,android-runtime,java-threads
int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button start = (Button) findViewById(R.id.start); start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Thread thread = new Thread(new Runnable() { @Override public void run() { try { String[] cmd = new String[] { "logcat", "-f",Environment.getExternalStorageDirectory()+"/log.txt", "-v", "time"...

Android - Difference between Thread and AsyncTask?

java,android,android-asynctask,android-handler,java-threads
In my app i have buttons, when clicked will query the database and show result on screen. The query action will normally take 1 ~ 3 sec. These buttons will be clicked very often. I've implemented this action on both AsyncTask and Thread but see very little different. However in...

Can I call a synchronized method that calls a non-synchronized method that calls a synchronized method?

java,multithreading,synchronization,java-threads
In Java using the synchronized keyword all within a single object and thread. Can I call a synchronized method that calls a non-synchronized method that calls a synchronized method, without the final synchronized method blocking for the first synchronized method to be completed?...

Possible execution result

java,multithreading,runnable,java-threads
public class Messager implements Runnable { public static void main(String[] args) { new Thread(new Messager("Wallace")).start(); new Thread(new Messager("Gromit")).start(); } private String name; public Messager(String name) { this.name = name; } public void run() { message(1); message(2); } private synchronized void message(int n) { System.out.print(name + "-" + n +...

Interaction with user on Thread cause my app crash [duplicate]

android,multithreading,java-threads
This question already has an answer here: Android “Only the original thread that created a view hierarchy can touch its views.” 9 answers My app crashes if TextView.setText is inside Thread: NOTE: The following class is inside of MainActivity. private class StreamThread extends Thread { public StreamThread() { }...

How can I programmatically cause a delay in Android?

java,android,timertask,android-handler,java-threads
I tried to use Thread.sleep() but it didn't work. When I use it, the app stops responding. I need to put some delays in my code like this: public void inicioJogo(){ for (int jogada = 1; jogada <= 50; jogada++) { for (int contador = 0; contador < jogada; contador++){...

Returning value from thread Java/ Android

java,android,java-threads
I have the following thread in my android class. How can I get the value of err from the thread??? public int method(){ new Thread(new Runnable() { int err; @Override public void run() { err = device.verify(30, 5, coderChoice, detectModeChoice, 0, listSearch, callbackCmd, MTFPSD.this, matchingScore); updateView("Finger Captured Successfully", err); }...