logo
down
shadow

DefaultMessageListenerContainer threading issue


DefaultMessageListenerContainer threading issue

By : Otto Sipe
Date : November 16 2020, 06:23 AM
will help you Although this question was asked long time ago. I too faced this issue recently. Posting the answer for other's benefit.
One needs to set the prefetch limit to 1. You can provide this in the connection string.
code :
tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1


Share : facebook icon twitter icon
C# threading issue

C# threading issue


By : user1594339
Date : March 29 2020, 07:55 AM
To fix this issue First, there is no need to create new threads inside DoWork; the whole idea with the BackgroundWorker is that DoWork is executed on a separate thread. Second, since DoWork is executed on a separate thread and UI controls can be modified only on the UI thread, you need to invoke those updates correctly. So, a rewritten version of worker_DoWork could look like this:
code :
void worker_DoWork(object sender, DoWorkEventArgs e)
{
    foreach (string line in textBox1.Lines)
    {  
        Dig digger = new Dig(line, textBox1.Text);
        digger.DomainChecked += new Dig.DomainCheckedHandler(OnUpdateTicker);
        string response = digger.GetAllInfo();
        richTextBox1.Invoke((Action) delegate { richTextBox1.AppendText(response); });
    }
}
Threading issue, simultaneous thread limit, maximum threads running at the same time issue

Threading issue, simultaneous thread limit, maximum threads running at the same time issue


By : Ho Lu Quoc Khai
Date : March 29 2020, 07:55 AM
it fixes the issue You are not using the ThreadPool- you are just starting up a Thread for each country:
code :
foreach (DataRow drLoop in dt.Rows) 
{
    Thread job = new Thread(new ParameterizedThreadStart(ThreadJob), 5);
    job.Start(drLoop["CountryName"].ToString());
}
foreach (DataRow drLoop in dt.Rows) 
    ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadJob), drLoop["CountryName"].ToString());
Ruby Threading Issue or No Threading Issue?

Ruby Threading Issue or No Threading Issue?


By : huhyun
Date : March 29 2020, 07:55 AM
wish help you to fix your issue With the official Ruby VM (YARV), there is no threading issue. YARV is completely thread-unsafe so essentially every time you touch a Ruby object the global VM lock (GVL) blocks all threads but one to prevent objects from being put into an invalid state due to multiple threads stepping on each other.
The only way this code could cause a problem is if updating an input object causes some side-effect in the VM's internal state, which conflicts with another thread that is concurrently updating a different input. But that is precisely what the GVL prevents.
API Threading Issue iOS

API Threading Issue iOS


By : Stephen Priestley
Date : March 29 2020, 07:55 AM
will help you getPlanet is performing an asynchronous call. The result instance will not hold the received data. Instead of that use a completion block in the getPlanet and on receiving the data invoke this completion block. Something like this. Do read on closures.
code :
class APICaller{

    weak var delegate:APIDelegate?

    func getCharacter(x:Int){
        let character = CharacterModel()
        let url = URL(string: "https://swapi.co/api/people/\(x)/")
        let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
            if error != nil{
                print("Error downloading character information. Empty character returned.")
            } else {
                if let content = data {

                    do{
                        let charJSON = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any]
                        character.name = (charJSON?["name"] as? String)?.description ?? ""
                        character.height = Int((charJSON?["height"] as? String)?.description ?? "0") ?? 0
                        character.mass = Int((charJSON?["mass"] as? String)?.description ?? "0") ?? 0
                        character.hairColor = (charJSON?["hair_color"] as? String)?.description ?? ""
                        character.skinColor = (charJSON?["skin_color"] as? String)?.description ?? ""
                        character.eyeColor = (charJSON?["eye_color"] as? String)?.description ?? ""
                        character.birthYear = (charJSON?["birth_year"] as? String)?.description ?? ""
                        character.gender = (charJSON?["gender"] as? String)?.description ?? ""
                        self.getPlanet(uri: (charJSON?["homeworld"] as? String)?.description ?? "", completion:
                            { (result:String) in
                                character.homeWorld = result
                                DispatchQueue.main.async {
                                    self.delegate?.didGetStarWarsCharacter(characterData:character)
                                }
                        }
                        )
                        //The homeward part of the response is another URL and as such requires another API Call to get anything meaningful

                    }catch{
                        print("Error downloading character information. Empty or incomplete character returned")
                    }
                }
            }
        }
        task.resume()
    }
    private func getPlanet(uri:String, completion:@escaping (_ response:String)->Void){
        if uri == ""{
            completion(uri) // return empty string if the original call doesn't get anything.
        }
        var result = ""
        let url = URL(string:uri)
        let task = URLSession.shared.dataTask(with: url!){(data,response,error)->Void in
            if error != nil{
                result = "No Planet Found"
            }else{
                if let planet = data{
                    do{
                        let planetJSON = try JSONSerialization.jsonObject(with: planet, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String:Any]
                        //print(planetJSON?["name"] as? String ?? "No Planet")
                        result = (planetJSON?["name"] as? String)?.description ?? "No Planet Found"
                    }catch{
                        result = "No Planet Found"
                    }
                    completion(result)
                }
            }
        }// end of task, result is lost due to multithreading
        task.resume()
    }
}
JavaFX not rendering earlier items in an array, unable to find issue, believe threading might be the issue

JavaFX not rendering earlier items in an array, unable to find issue, believe threading might be the issue


By : user3164081
Date : March 29 2020, 07:55 AM
hope this fix your issue I would suggest you use Timeline instead of Thread. It can be done using a Thread, but Timeline is designed for cases like this.
code :
public void drawLine(int x1, int y1, int x2, int y2, Stage primStage, GraphicsContext gc)
{

    ArrayList<Integer[]> points = calculateLine(x1, y1, x2, y2, gc);
    PositionCounter position = new PositionCounter();

    int dy = Math.abs(y2 - y1);
    int dx = Math.abs(x2 - x1);
    int m = (dy >= dx) ? dy : dx;

    AtomicInteger counter = new AtomicInteger();
    Timeline animationTimeline = new Timeline(new KeyFrame(Duration.millis(20), (ActionEvent t) -> {
        position.setPosition(counter.getAndIncrement());
        fillPosition(points, gc, position.position);
    }));
    animationTimeline.setCycleCount(points.size());
    animationTimeline.play();

}
import com.sun.jdi.ArrayReference;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.util.Duration;

class PositionCounter
{

    public int position;

    public void setPosition(int newPos)
    {
        position = newPos;
    }
}

public class JavaFXTestingGround extends Application
{

//    public void drawRectangle(int x1, int y1, int x2, int y2, Stage primStage, GraphicsContext gc){
//        drawLine(x1, y2, x2, y2 , primStage, gc);
//        drawLine(x1, y1, x2, y2, primStage, gc);
//        drawLine(x1, y1, x1 , y2, primStage, gc);
//        drawLine(x2, y1, x2 , y2, primStage, gc);
//        drawLine(x1, y1, x2, y1 , primStage, gc);
//
//    }
//
    public void fillPosition(ArrayList<Integer[]> points, GraphicsContext gc, int positionInArray)
    {
        gc.fillRect(points.get(positionInArray)[0], points.get(positionInArray)[1], squareWidth / 2, squareWidth / 2);
        //System.out.println("(" + points.get(positionInArray)[0] + ", " + points.get(positionInArray)[1]);
    }

    public void drawLine(int x1, int y1, int x2, int y2, Stage primStage, GraphicsContext gc)
    {

        ArrayList<Integer[]> points = calculateLine(x1, y1, x2, y2, gc);
        PositionCounter position = new PositionCounter();

        int dy = Math.abs(y2 - y1);
        int dx = Math.abs(x2 - x1);
        int m = (dy >= dx) ? dy : dx;

        AtomicInteger counter = new AtomicInteger();
        Timeline animationTimeline = new Timeline(new KeyFrame(Duration.millis(20), (ActionEvent t) -> {
            position.setPosition(counter.getAndIncrement());
            fillPosition(points, gc, position.position);
        }));
        animationTimeline.setCycleCount(points.size());
        animationTimeline.play();

    }

    @Override
    public void start(Stage primaryStage) throws Exception
    {

        //STUFF
        Group root = new Group();
        Scene scene = new Scene(root, 400, 400);
        scene.setFill(Color.GOLD);

        Canvas canvas = new Canvas(400, 400);
        GraphicsContext gc = canvas.getGraphicsContext2D();

        root.getChildren().add(canvas);
        //////////

        gc.fillRect(0, 200, 400, 1);
        gc.fillRect(0, 100, 400, 1);
        gc.fillRect(0, 300, 400, 1);
        gc.fillRect(200, 0, 1, 400);
        gc.fillRect(100, 0, 1, 400);
        gc.fillRect(300, 0, 1, 400);

        // drawRectangle(50, 50, 350, 250, primaryStage, gc);
        //drawLine(50, 250, 350, 250 , primaryStage, gc);
        //drawLine(50, 50, 350, 250, primaryStage, gc);
        //drawLine(50, 50, 50 , 250, primaryStage, gc);
        //drawLine(350, 50, 350 , 250, primaryStage, gc);
        drawLine(50, 50, 350, 50, primaryStage, gc);

        //////////
        primaryStage.setScene(scene);
        primaryStage.show();
        /////////
    }

    int squareWidth = 2;

    public ArrayList<Integer[]> calculateLine(int x1, int y1, int x2, int y2, GraphicsContext gc)
    {

        ArrayList<Integer[]> points = new ArrayList<Integer[]>();

        int dy = Math.abs(y2 - y1);
        int dx = Math.abs(x2 - x1);

        int sx = (x1 < x2) ? 1 : -1;
        int sy = (y1 < y2) ? 1 : -1;

        int err = dx - dy;
        int x = x1;
        int y = y1;
        int e2 = 0;

        Integer[] pos = new Integer[2];
        pos[0] = x;
        pos[1] = y;
        points.add(pos);

        int m = (dy >= dx) ? dy : dx;

        for (int i = 0; i <= m; i++) {

            e2 = 2 * err;
            if (e2 > -dy) {
                err = err - dy;
                x = x + sx;
                Integer[] position = new Integer[2];
                position[0] = x;
                position[1] = y;
                points.add(position);
            }

            if (e2 < dx) {
                err = err + dx;
                y = y + sy;
                Integer[] position = new Integer[2];
                position[0] = x;
                position[1] = y;
                points.add(position);
            }

        }

        return points;
    }

    public static void main(String[] args)
    {
        launch(args);
    }
}
Related Posts Related Posts :
  • How to implement Generics DAO with Spring JDBC template
  • Escaping a | (pipe) in SpEL
  • Spring: Using @Qualifier with Property Placeholder
  • abount the singleton beans of spring
  • Spring @Autowired Not Working Error Creating Bean Injection Of Autowire dependencies failed
  • Spring-MVC Exception handler returns OK when writing into response
  • My applicationContext.xml is not valid when i deploy my project on tomcat7:org.springframework.beans.factory.parsing.Bea
  • Storing trailing zeroes in database with JPA and Oracle
  • Making specific method non transactional in Spring
  • Spring more than one profile and ${spring.profiles.active}
  • Spring Batch - interrupt thread when job stops
  • Can I use spring AOP to log start and end of a method to help easy debuging
  • How to use different error codes for validation messages?
  • Spring Data Rest and collections with unique constraints
  • Thymeleaf + Spring Checkboxes not binding
  • Spring Boot: Publish Thymeleaf template without restarting the server
  • How long will Spring 3.x continue to be supported?
  • Spring Security without a login form
  • SOAP UI not finding WSDL depending XSD files in Spring WS Soap Service
  • Spring MVC- Joda datetime error message for invalid date
  • Broadleaf Demosite on JBOSS 7
  • Spring Mongo mapping variable data
  • MySQL and Infinispan - JTA implementation
  • spring boot autoconfiguration with jdbc template autowiring dataSource issue
  • Hibernate and @SessionAttribute
  • Good sample spring and hibernate web application book?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org