FLIR One Developer / Blog / Topics / android, flir gen 2 / Concurrency issues with RenderedImage and android threadpool

Concurrency issues with RenderedImage and android threadpool

Home Forums FLIR ONE SDK Development Android development Concurrency issues with RenderedImage and android threadpool

Tagged: ,

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Amit Amit 2 years ago.

Viewing 1 post (of 1 total)

  • Author


  • #7676

    Profile photo of Amit


    I am using android’s thread pool executor framework (initialized as below).

    BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
    ExecutorService executorService = new ThreadPoolExecutor(totalCores, totalCores * 3, 10, TimeUnit.SECONDS, taskQueue);

    Consider the following function onFrameProcessed –

    public void onFrameProcessed(RenderedImage renderedImage) {
    String timeNow = new SimpleDateFormat("d-M-Y_HH_mm_ss_SSS").format(new Date()).toString();
    CustomRunnable3 customRunnable3 = new CustomRunnable3(renderedImage, timeNow);

    Definition of CustomRunnable3 is as follows:

    class CustomRunnable3 implements Runnable {
        RenderedImage renderedImageLocal;
        String basePath, timeNowCopy;
        int hashCode;
        CustomRunnable3(RenderedImage renderedImage, String timeNow) {
            renderedImageLocal = renderedImage;
            this.basePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
            this.timeNowCopy = timeNow;
            hashCode = renderedImageLocal.hashCode();
        public void run() {
            if (renderedImageLocal.imageType() == RenderedImage.ImageType.ThermalRadiometricKelvinImage) {
                int[] thermalData = renderedImageLocal.thermalPixelValues();
                String dataPath = basePath + "/" + this.timeNowCopy + ".csv";
                try {
                    PrintWriter printWriter = new PrintWriter(dataPath);
                    int dataLen = thermalData.length;
                    for (int i = 0; i < dataLen; i++) {
                } catch (IOException e) {
                String imgPath = basePath + "/" + this.timeNowCopy + ".jpg";
                try {
                    renderedImageLocal.getFrame().save(new File(imgPath), frameProcessor);
                } catch (IOException e) {

    Usage Scenario : onFrameReceived is being called multiple times per second(like 4-5 times). In each call to onFrameReceived, I am saving two files from renderedImage object (1 csv file, 1 jpg file). Both of these files must be related to each other because both are created from one parent and have same name(except the extension).

    Problem : But that is not happening and somehow I am ending up with jpg file content from 1 renderedImage and csv content from another renderedImage object. What are the possible reasons for this problem, please share your opinion.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.