Questions tagged as 'thread'

1
answer

How to solve java.lang.NullPointerException?

I created the class Server ! However, an exception of type java.lang.NullPointerException is thrown! Could anyone help me with this problem? The class is as follows: public class Server { public static final int SERVERPORT...
asked by 15.01.2015 / 02:17
3
answers

Print Thread ID

I have the following code and I can not print the ID of the Thread, just the size. How do I print the thread array ID? public class MultiplicacaoMatrizesThread { // Matriz A public static int a[][] = { { 5, 4 }, { 3, 3 }, { 2, 4 } }; // Matriz...
asked by 15.03.2016 / 17:41
1
answer

Implement Runnable or Extend Thread?

In several Java projects, I've seen these two ways to create Threads: With implements Runnable : public class MyRunnable implements Runnable { public void run() { //Código } } //Iniciada com uma chamada "new Thread(new...
asked by 04.04.2017 / 16:50
1
answer

How to write this java program using javascript and node? [closed]

public class Principal { private static int x = 0; private static int y = 0; public static void sum() { x = y + 1; y = x + 1; } public static void main(String[] args) { for (int i = 1; i <= 10; i++) { Thread a = new Th...
asked by 06.10.2016 / 20:04
2
answers

Background thread when the app is closed

How do I run a Thread with the application closed? That is, so that when the user turns on the device it starts without it having to enter the application.     
asked by 16.06.2015 / 16:48
2
answers

Execute N threads and know when they all finished executing

I have the following problem, I need to run the same N method in a for and know when all the threads have already finished running it. I needed something like this: foreach (MeuObjeto obj in lstObj) { new Thread(delegate() { Me...
asked by 11.04.2015 / 01:06
1
answer

Thread lifetime in java

When an object, from a class that implements a thread, is destroyed (loses reference) does the thread for that object stop?     
asked by 06.07.2016 / 14:54
1
answer

Create instance of classes in threads

Imagine that I have a class: Class Animal { //Propriedades } Now creating multiple instances of the class I do as follows: Animal[] animais = new Animal[10]; for(int i = 0; i < 10; i++) { animais[i] = new Animal(); } So far,...
asked by 02.12.2016 / 11:20
1
answer

Using a ThreadPool or just initializing a new Thread?

Let's say that the software all the time creates a new Runnable to perform a basic function every cycle, at the end of a day of execution I would have a few hundred Threads of this function created and finalized correctly by the JVM. W...
asked by 04.04.2018 / 14:52
2
answers

Thread containing database connection components throws exception when they are released from memory

I needed to add some threads to perform certain processes in the background. This thread accesses the methods of a WebService and also performs operations on the database. I create all the objects I need to use in this thread within itself to...
asked by 06.10.2014 / 18:59