multithreading – Java create a thread with parameters

I have a program that counts a word in the text more than once.
I want the loop to be in a separate thread. How can I pass the articls and stringToSearch parameters to the thread or define the global parameters?

public class Main {
    public static void main(String() args)  {
        Scanner s = new Scanner(;
        int numberArticles = s.nextInt();
articles = new ArrayList<>(); for(int i = 0; i < numberArticles; i++) { String articleName = s.nextLine(); String content = ""; File file = new File(articleName + ".txt"); BufferedReader br; try { br = new BufferedReader(new FileReader(file)); String st; while ((st = br.readLine()) != null) { content += st; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } articles.add(new Article(articleName, content)); } String stringToSearch = s.nextLine(); MyThread myThread = new MyThread(); myThread.start(); } } public class MyThread extends Thread { public void run(){ for(Article article : articles) { int counter = 0; String() words = article.getContent().split(" "); for (String word : words) { if(word.equals(stringToSearch)) { counter++; } } } } }

c # – Android.Util.AndroidRuntimeException: & # 39; Only the original thread that created a view hierarchy can touch its views. & # 39;

RecuperaPayload = FindViewById (Resource.Id.editTextMultilinhas);



.Where (msg => msg.Topic == "topic1")

.Sign up (msg =>


Console.WriteLine($"Resposta da chamada original  = {msg.Topic} mensagem  =  

{Encoding.UTF8.GetString (msg.Payload)} ");

Console.WriteLine($"Resposta do MQTT = {Encoding.UTF8.GetString(msg.Payload)}");

string Base;

Base = $"{Encoding.UTF8.GetString(msg.Payload)}";                     

RecuperaPayload.Text = Base;

it manages to run the editor and the payload presenting the data in Edittext.text but hangs on the line returning the execution to the IDE:

RecoverPayload.Text = Base;

giving the following error message: Android.Util.AndroidRuntimeException:

"Only the original feed that created a view hierarchy can touch its views."

parallel computing – Why didn't the most dominant programming languages ​​follow the CSP thread model?

There are many approaches to competition, with different tradeoffs. We have threads with a shared mutable state (for example, a SRC style thread). We have coroutines (like Go). We have models of actors with independent processes communicating via the passing of messages (like Erlang or E).

I would put CSP on a different level. It is not the same thing. The form of CSP that I know is a mathematical and theoretical formalism which can be used to model competing systems. It is not really a programming model that can be used directly in programming languages. It's more like lambda calculus. You can create programming language APIs inspired by CSP, just like Lisp and Scheme are inspired by lambda computation, but this is not directly the design of a thread API itself.

Why did the first languages ​​choose to follow the SRC model rather than something inspired by the CSP? Well, all I can share with you is speculation. The SRC model is a low-level model that fairly closely matches the primitives provided by processors: it is a thin level of abstraction compared to that. Just as C is a thin layer on assembly language (and does not use, for example, functional or declarative paradigms), it is not surprising that the first languages ​​provide a thin layer on processor primitives (rather than, say, other theoretical paradigms). In addition, the SRC model works well with existing code and existing programming languages. You can take the existing sequential code and then add threads. When you write threaded code, the sequential part of the calculation looks like code written for a non-threaded language. This backward compatibility and familiarity was probably important. The SRC model could be deployed as a library, without requiring modifications to the syntax of the programming language or the compilers. I have to imagine that this could have been an important factor in its adoption. In addition, the SRC model is somewhat similar in many ways to existing Unix primitives for running code in parallel in multiple processes, which, I imagine, would also have been beneficial for adoption. It's just my speculation. Maybe someone else can provide a more documented answer.

zetservers [split from old thread]

zetservers is the worst and cheating hosting. do not use this bad accommodation.

They promised us that they would ignore any DMCA report and that they would never suspend my server. but at the first DMCA report, they terminate the server without notice.

In addition, their support is really bad and unprofessional. They stole my money and ended the server (I paid 3 months in advance) but after only 10 days, they ended the server and took my money

You can see people talking about their scam on many forums

The salo member of WJ also hacked them and has information about their customers. so nothing sure now with zetservers

How do I find a specific word in a discussion thread in Gmail for Android?

I opened a discussion thread (or conversation) in Microsoft Outlook for Android. I want to search for a channel (for example, a word or a phrase).

How do I find a specific word in a discussion thread in Gmail for Android?

Is opening a new thread for each event you want to handle the best way to handle events?

I know 100% that there is already a solution for what I ask, but with all the research I have done, I can't seem to find it.

Currently, a CS student is trying to do independent studies to stay ahead. Recently, I have wondered how different languages ​​/ frameworks implement event handling and I have found information on this, as there is usually an event loop working synchronously with the main thread.

My question is how such a thing is implemented when you want to check multiple events such as game events. Would you like to create a thread for each event and have these threads looped synchronously with the main thread or want you have a single thread? I'm just assuming it's better to open a new thread for each event you want to handle, but there has to be a better solution.

Spring Boot – The scope & # 39; request & # 39; is not active for the current thread when using @Async

Getting below the error.

Error creating bean with name & # 39; scopedTarget.domainMetadata & # 39;: the scope & # 39; request & # 39; is not active for the current thread; consider setting a scope proxy for this bean if you intend to refer to it from a s … "," level ":" ERROR "," logger ":" org. springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler "," thread ":" SimpleAsyncTaskExecutor-3 "," throwable_class ":" FatalBeanException "," throwable_root_cause_class ":" java.lang.IllegalStateException "}

multithreading – Java implementation task on another thread with promise of javascript type resolve-reject


I have a TCP game server, which the player requests to connect to. However, the game server does not manage the authentication part of the connection process, it rather uses an external micro-service which is an HTTP server to see if the user can authenticate with the credentials. data identification.

Now why is this a problem? – Well, I use the network framework, which is a non-blocking framework, it manages all the connections in a sequence on the same thread. Since I do not want to cause delays, I will not send HTTP requests on the same thread because I do not want to stop it.

Instead, I followed a pattern of reminders like the resolve-reject promise java script, and I'd love to hear what you think, and if it could be done better.

Don't mind the generic types, just take the basic idea:

First of all, this is my ServiceProvider, the purpose of this class is to provide a singleton of each service that interacts with microservices such as UserService which is an HTTP server to manage everything related to the user (authentication, data, etc.):

public class ServiceProvider {

    private static ExecutorService executorService = Executors.newFixedThreadPool(ServicesConfig.SERVICES_THREAD_POOL_CAPACITY);

    private static UserService userService;

     * Provdes an user service singleton instance
     * @return  The user service
    public static UserService getUserService() {
        if (userService == null) {
            userService = new UserService();
        return userService;

    public static void submitServiceTask(ServicePromise task) {

Second, this is my UserService for example:

public class UserService extends HeroesHttpService {

     * Authenticates an user
     * @param username  The username
     * @param password  The password
     * @return  ?
    public ServicePromise authenticateUser(String username, String password) {

        ServicePromise promise = new ServicePromise() {
            public void run() {
                HttpClient client = HttpClients.createDefault();

                HttpGet request = new HttpGet(getBaseUrl() + "/user/authenticate");
                try {
                    HttpResponse response = client.execute(request);
                } catch (IOException e) {

        return promise;

Now here is my promise interface:

public abstract class ServicePromise implements Runnable {

    private ServicePromiseCallback callback;

    public ServicePromise then(ServicePromiseCallback cb) {
        this.callback = cb;
        return this;

    public void run() {

    public void resolve(T data) {
        if (this.callback == null) {

    public void reject(T data) {
        if (this.callback == null) {

And this is the callback interface:

public interface ServicePromiseCallback {
    void onResolve(T response);
    void onReject(T response);

And finally, this is how I use it:

    ServiceProvider.getUserService().authenticateUser(player.playerName, player.playerPass).then(new ServicePromiseCallback () {
        public void onResolve(Object response) {


        public void onReject(Object response) {


Again, don't deal with the resolution / rejection types, this is definitely going to be AuthenticateUserResponseDto and so on, but it doesn't matter right now

magento2.3.3 – how to display the image on the Ariane thread in the category

hi i am currently looking for a solution to add the catg image on the Ariane thread. i added a static block inside catg and displaying both catg and product is there a solution for that.

I just want this picture above the Ariadne thread.
Thanks in advance

enter description of image here

I tried to replace the breadcrumbs.phtml file in my custom theme and I called a static block and the result works fine on the catg page but this image is also visible on the home page , which I don't want.
my phtml file


please refer to the picture below
enter description of image here

enter description of image here

i have already solved this problem thanks if anyone needs and can post a question and i will help her

working .phtml code

Kotlin coroutines – how to run in the background and use the result in the calling thread?

The main idea is to have an unsprung function runInBackgroundAndUseInCallerThread(callback: (SomeModel) -> Unit) that execute certain jobs asynchronously in the background (another thread) and after work – execute the callback in the caller's thread (thread that started) runInBackgroundAndUseInCallerThread).

Below, I wrote a sample code, but I don't know how correct it is and if it is possible at all. With the println("1/2/3/...") I have marked the desired call order.
getDispatcherFromCurrentThread – if it is possible to implement this function, then the solution can be used, but i don't know how to implement it and is it fair to do it like that at all.

Therefore, do not see it as the only solution.

import kotlinx.coroutines.*
import kotlin.concurrent.thread

fun main() {
    runInBackgroundAndUseInCallerThread {
        println("Hello ${it.someField} from ${Thread.currentThread().name}") // should be "Hello TestField from main"
    thread(name = "Second thread") {
        runInBackgroundAndUseInCallerThread {
            println("Hello ${it.someField} from ${Thread.currentThread().name}") // should be "Hello TestField from Second thread"

fun runInBackgroundAndUseInCallerThread(callback: (SomeModel) -> Unit) {
    val dispatcherFromCallerThread: CoroutineDispatcher = getDispatcherFromCurrentThread()
    CoroutineScope(Dispatchers.IO).launch {
        val result: SomeModel = getModelResult()
        launch(dispatcherFromCallerThread) { callback(result) }

data class SomeModel(val someField: String)

suspend fun getModelResult(): SomeModel {
    return SomeModel("TestField")

fun getDispatcherFromCurrentThread(): CoroutineDispatcher {
    // TODO: Create dispatcher from current thread... How to do that?