Example usage for java.util.concurrent Executors newSingleThreadExecutor

List of usage examples for java.util.concurrent Executors newSingleThreadExecutor

Introduction

In this page you can find the example usage for java.util.concurrent Executors newSingleThreadExecutor.

Prototype

public static ExecutorService newSingleThreadExecutor() 

Source Link

Document

Creates an Executor that uses a single worker thread operating off an unbounded queue.

Usage

From source file:com.jivesoftware.os.amza.deployable.Main.java

public void run(String[] args) throws Exception {

    String hostname = args[0];/*from  w  w w .  ja  va2 s.  co  m*/
    String clusterName = (args.length > 1 ? args[1] : "unnamed");
    String hostPortPeers = (args.length > 2 ? args[2] : null);

    int port = Integer.parseInt(System.getProperty("amza.port", "1175"));
    String multicastGroup = System.getProperty("amza.discovery.group", "225.4.5.6");
    int multicastPort = Integer.parseInt(System.getProperty("amza.discovery.port", "1223"));

    String logicalName = System.getProperty("amza.logicalName", hostname + ":" + port);
    String datacenter = System.getProperty("host.datacenter", "unknownDatacenter");
    String rack = System.getProperty("host.rack", "unknownRack");

    RingMember ringMember = new RingMember(logicalName);
    RingHost ringHost = new RingHost(datacenter, rack, hostname, port);

    // todo need a better way to create writer id.
    int writerId = Integer.parseInt(System.getProperty("amza.id", String.valueOf(new Random().nextInt(512))));

    SnowflakeIdPacker idPacker = new SnowflakeIdPacker();
    JiveEpochTimestampProvider timestampProvider = new JiveEpochTimestampProvider();
    final TimestampedOrderIdProvider orderIdProvider = new OrderIdProviderImpl(
            new ConstantWriterIdProvider(writerId), idPacker, timestampProvider);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, false);

    final AmzaServiceConfig amzaServiceConfig = new AmzaServiceConfig();
    final AmzaStats amzaSystemStats = new AmzaStats();
    final AmzaStats amzaStats = new AmzaStats();
    final SickThreads sickThreads = new SickThreads();
    final SickPartitions sickPartitions = new SickPartitions();

    AtomicInteger systemRingSize = new AtomicInteger(-1);
    amzaServiceConfig.workingDirectories = System.getProperty("amza.working.dirs", "./data1,./data2,./data3")
            .split(",");
    amzaServiceConfig.systemRingSize = Integer.parseInt(System.getProperty("amza.system.ring.size", "-1"));
    if (amzaServiceConfig.systemRingSize > 0) {
        systemRingSize.set(amzaServiceConfig.systemRingSize);
    }

    AmzaInterner amzaInterner = new AmzaInterner();

    PartitionPropertyMarshaller partitionPropertyMarshaller = new PartitionPropertyMarshaller() {
        @Override
        public PartitionProperties fromBytes(byte[] bytes) {
            try {
                return mapper.readValue(bytes, PartitionProperties.class);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }

        @Override
        public byte[] toBytes(PartitionProperties partitionProperties) {
            try {
                return mapper.writeValueAsBytes(partitionProperties);
            } catch (JsonProcessingException ex) {
                throw new RuntimeException(ex);
            }
        }
    };

    //  hmmm
    LABPointerIndexConfig labConfig = BindInterfaceToConfiguration.bindDefault(LABPointerIndexConfig.class);
    labConfig.setLeapCacheMaxCapacity(
            Integer.parseInt(System.getProperty("amza.leap.cache.max.capacity", "1000000")));

    BinaryPrimaryRowMarshaller primaryRowMarshaller = new BinaryPrimaryRowMarshaller(); // hehe you cant change this :)
    BinaryHighwaterRowMarshaller highwaterRowMarshaller = new BinaryHighwaterRowMarshaller(amzaInterner);

    AtomicReference<Callable<RingTopology>> topologyProvider = new AtomicReference<>(); // bit of a hack

    InstanceDescriptor instanceDescriptor = new InstanceDescriptor(datacenter, rack, "", "", "", "", "", "", "",
            "", 0, "", "", "", 0L, true);
    ConnectionDescriptorsProvider connectionsProvider = (connectionDescriptorsRequest,
            expectedReleaseGroup) -> {
        try {
            RingTopology systemRing = topologyProvider.get().call();
            List<ConnectionDescriptor> descriptors = Lists.newArrayList(Iterables.transform(systemRing.entries,
                    input -> new ConnectionDescriptor(instanceDescriptor, false, false,
                            new HostPort(input.ringHost.getHost(), input.ringHost.getPort()),
                            Collections.emptyMap(), Collections.emptyMap())));
            return new ConnectionDescriptorsResponse(200, Collections.emptyList(), "", descriptors,
                    connectionDescriptorsRequest.getRequestUuid());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    TenantsServiceConnectionDescriptorProvider<String> connectionPoolProvider = new TenantsServiceConnectionDescriptorProvider<>(
            Executors.newScheduledThreadPool(1), "", connectionsProvider, "", "", 10_000); // TODO config
    connectionPoolProvider.start();

    TenantAwareHttpClient<String> httpClient = new TenantRoutingHttpClientInitializer<String>(null)
            .builder(connectionPoolProvider, new HttpDeliveryClientHealthProvider("", null, "", 5000, 100))
            .deadAfterNErrors(10).checkDeadEveryNMillis(10_000).maxConnections(1_000)
            .socketTimeoutInMillis(60_000).build(); //TODO expose to conf

    AvailableRowsTaker availableRowsTaker = new HttpAvailableRowsTaker(httpClient, amzaInterner, mapper); // TODO config
    AquariumStats aquariumStats = new AquariumStats();

    AmzaService amzaService = new AmzaServiceInitializer().initialize(amzaServiceConfig, amzaInterner,
            aquariumStats, amzaSystemStats, amzaStats,
            new HealthTimer(CountersAndTimers.getOrCreate("quorumLatency"), "quorumLatency",
                    new NoOpHealthChecker<>("quorumLatency")),
            () -> amzaServiceConfig.systemRingSize, sickThreads, sickPartitions, primaryRowMarshaller,
            highwaterRowMarshaller, ringMember, ringHost, Collections.emptySet(), orderIdProvider, idPacker,
            partitionPropertyMarshaller, (workingIndexDirectories, indexProviderRegistry,
                    ephemeralRowIOProvider, persistentRowIOProvider, partitionStripeFunction) -> {
                indexProviderRegistry
                        .register(
                                new BerkeleyDBWALIndexProvider(BerkeleyDBWALIndexProvider.INDEX_CLASS_NAME,
                                        partitionStripeFunction, workingIndexDirectories),
                                persistentRowIOProvider);

                indexProviderRegistry.register(new LABPointerIndexWALIndexProvider(amzaInterner, labConfig,
                        Executors.newCachedThreadPool(), Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool(), Executors.newCachedThreadPool(),
                        LABPointerIndexWALIndexProvider.INDEX_CLASS_NAME, partitionStripeFunction,
                        workingIndexDirectories), persistentRowIOProvider);
            }, availableRowsTaker, () -> {
                return new HttpRowsTaker("system", amzaStats, httpClient, mapper, amzaInterner,
                        Executors.newSingleThreadExecutor(), Executors.newCachedThreadPool());
            }, () -> {
                return new HttpRowsTaker("striped", amzaStats, httpClient, mapper, amzaInterner,
                        Executors.newSingleThreadExecutor(), Executors.newCachedThreadPool());
            }, Optional.absent(), (changes) -> {
            }, (threadCount, name) -> {
                return Executors.newCachedThreadPool();
            });

    topologyProvider.set(() -> amzaService.getRingReader().getRing(AmzaRingReader.SYSTEM_RING, -1));

    TailAtScaleStrategy tailAtScaleStrategy = new TailAtScaleStrategy(
            BoundedExecutor.newBoundedExecutor(1024, "tas"), 100, // TODO config
            95, // TODO config
            1000 // TODO config
    );

    AmzaClientProvider<HttpClient, HttpClientException> clientProvider = new AmzaClientProvider<>(
            new HttpPartitionClientFactory(),
            new HttpPartitionHostsProvider(httpClient, tailAtScaleStrategy, mapper),
            new RingHostHttpClientProvider(httpClient), BoundedExecutor.newBoundedExecutor(1024, "amza-client"),
            10_000, //TODO expose to conf
            -1, -1);

    final JerseyEndpoints jerseyEndpoints = new JerseyEndpoints().addEndpoint(AmzaEndpoints.class)
            .addInjectable(AmzaService.class, amzaService).addEndpoint(AmzaReplicationRestEndpoints.class)
            .addInjectable(AmzaInstance.class, amzaService).addEndpoint(AmzaClientRestEndpoints.class)
            .addInjectable(AmzaInterner.class, amzaInterner).addInjectable(ObjectMapper.class, mapper)
            .addInjectable(AmzaClientService.class, new AmzaClientService(amzaService.getRingReader(),
                    amzaService.getRingWriter(), amzaService));

    new AmzaUIInitializer().initialize(clusterName, ringHost, amzaService, clientProvider, aquariumStats,
            amzaStats, timestampProvider, idPacker, amzaInterner, new AmzaUIInitializer.InjectionCallback() {
                @Override
                public void addEndpoint(Class clazz) {
                    System.out.println("Adding endpoint=" + clazz);
                    jerseyEndpoints.addEndpoint(clazz);
                }

                @Override
                public void addInjectable(Class clazz, Object instance) {
                    System.out.println("Injecting " + clazz + " " + instance);
                    jerseyEndpoints.addInjectable(clazz, instance);
                }

                @Override
                public void addSessionAuth(String... paths) throws Exception {
                    System.out.println("Ignoring session auth request for paths: " + Arrays.toString(paths));
                }
            });

    InitializeRestfulServer initializeRestfulServer = new InitializeRestfulServer(false, port, "AmzaNode",
            false, null, null, null, 128, 10000);
    initializeRestfulServer.addClasspathResource("/resources");
    initializeRestfulServer.addContextHandler("/", jerseyEndpoints);
    RestfulServer restfulServer = initializeRestfulServer.build();
    restfulServer.start();

    System.out.println("-----------------------------------------------------------------------");
    System.out.println("|      Jetty Service Online");
    System.out.println("-----------------------------------------------------------------------");

    amzaService.start(ringMember, ringHost);

    System.out.println("-----------------------------------------------------------------------");
    System.out.println("|      Amza Service Online");
    System.out.println("-----------------------------------------------------------------------");

    if (clusterName != null) {
        if (hostPortPeers != null) {
            System.out.println("-----------------------------------------------------------------------");
            System.out.println("|     Amza Service is in manual Discovery mode. Cluster Name:" + clusterName);
            String[] peers = hostPortPeers.split(",");
            for (String peer : peers) {
                String[] hostPort = peer.trim().split(":");
                if (hostPort.length != 2 && hostPort.length != 3) {
                    System.out.println("|     Malformed peer:" + peer
                            + " expected form: <host>:<port> or <logicalName>:<host>:<port>");
                } else {
                    String peerLogicalName = (hostPort.length == 2) ? hostPort[0] + ":" + hostPort[1]
                            : hostPort[0];
                    String peerHostname = (hostPort.length == 2) ? hostPort[0] : hostPort[1];
                    String peerPort = (hostPort.length == 2) ? hostPort[1] : hostPort[2];

                    RingMember peerRingMember = new RingMember(peerLogicalName);
                    RingHost peerRingHost = new RingHost("unknown", "unknown", peerHostname,
                            Integer.parseInt(peerPort));

                    System.out.println("|     Adding ringMember:" + peerRingMember + " on host:" + peerRingHost
                            + " to cluster: " + clusterName);
                    amzaService.getRingWriter().register(peerRingMember, peerRingHost, writerId, false);
                }
            }
            systemRingSize.set(1 + peers.length);
            System.out.println("-----------------------------------------------------------------------");
        } else {
            AmzaDiscovery amzaDiscovery = new AmzaDiscovery(amzaService.getRingReader(),
                    amzaService.getRingWriter(), clusterName, multicastGroup, multicastPort, systemRingSize);
            amzaDiscovery.start();
            System.out.println("-----------------------------------------------------------------------");
            System.out.println("|      Amza Service Discovery Online: Cluster Name:" + clusterName);
            System.out.println("-----------------------------------------------------------------------");
        }
    } else {
        System.out.println("-----------------------------------------------------------------------");
        System.out.println("|     Amza Service is in manual Discovery mode.  No cluster name was specified");
        System.out.println("-----------------------------------------------------------------------");
    }
}

From source file:com.streamsets.pipeline.stage.origin.kafka.TestKafkaSource.java

@Test
public void testProduceJsonRecordsMultipleObjectsMultipleRecord()
        throws StageException, IOException, InterruptedException {

    CountDownLatch startLatch = new CountDownLatch(1);
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.submit(new ProducerRunnable(TOPIC4, SINGLE_PARTITION, producer, startLatch, DataType.JSON,
            StreamingJsonParser.Mode.MULTIPLE_OBJECTS, -1, null));

    KafkaConfigBean conf = new KafkaConfigBean();
    conf.metadataBrokerList = sdcKafkaTestUtil.getMetadataBrokerURI();
    conf.topic = TOPIC4;//w w  w. ja  v a 2s . co m
    conf.consumerGroup = CONSUMER_GROUP;
    conf.zookeeperConnect = zkConnect;
    conf.maxBatchSize = 9;
    conf.maxWaitTime = 5000;
    conf.kafkaConsumerConfigs = null;
    conf.produceSingleRecordPerMessage = false;
    conf.dataFormat = DataFormat.JSON;
    conf.dataFormatConfig.charset = "UTF-8";
    conf.dataFormatConfig.removeCtrlChars = false;
    conf.dataFormatConfig.jsonContent = JsonMode.MULTIPLE_OBJECTS;
    conf.dataFormatConfig.jsonMaxObjectLen = 4096;

    SourceRunner sourceRunner = new SourceRunner.Builder(StandaloneKafkaSource.class, createSource(conf))
            .addOutputLane("lane").build();

    sourceRunner.runInit();

    startLatch.countDown();
    List<Record> records = new ArrayList<>();
    StageRunner.Output output = getOutputAndRecords(sourceRunner, 12, "lane", records);

    shutDownExecutorService(executorService);

    String newOffset = output.getNewOffset();
    Assert.assertNull(newOffset);
    Assert.assertEquals(12, records.size());

    sourceRunner.runDestroy();
}

From source file:io.nats.connector.plugins.redis.RedisPubSubPlugin.java

@Override
public boolean onNatsInitialized(NATSConnector connector) {
    this.connector = connector;

    if (subjectsToChannels == null && channelsToSubjects == null) {
        logger.error("No subject/channel mapping has been defined.");
        return false;
    }/* w w w  .j a v a2  s.  c  o  m*/

    try {
        if (subjectsToChannels != null) {
            for (String s : subjectsToChannels.keySet()) {
                connector.subscribe(s);
            }
        }
    } catch (Exception e) {
        logger.error("NATS Subscription error", e);
        return false;
    }

    if (channelsToSubjects != null) {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(new ListenForRedisUpdates());
    }

    return true;
}

From source file:com.concentricsky.android.khanacademy.util.OfflineVideoManager.java

/**
 * Cancel ongoing and enqueued video downloads.
 *//*from www.jav  a 2  s. c o  m*/
public void cancelAllVideoDownloads() {
    final DownloadManager dlm = getDownloadManager();
    final DownloadManager.Query q = new DownloadManager.Query();
    q.setFilterByStatus(DownloadManager.STATUS_FAILED | DownloadManager.STATUS_PAUSED
            | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);

    // Cancel all tasks - we don't want any more downloads enqueued, and we are
    // beginning a cancel task so we don't need any previous one.
    queueExecutor.shutdownNow();
    queueExecutor = Executors.newSingleThreadExecutor();

    new AsyncTask<Void, Void, Integer>() {
        @Override
        protected void onPreExecute() {
            doToast("Stopping downloads...");
        }

        @Override
        protected Integer doInBackground(Void... arg) {
            int result = 0;
            if (isCancelled())
                return result;

            Cursor c = dlm.query(q);
            Long[] removed = new Long[c.getCount()];
            int i = 0;
            while (c.moveToNext()) {
                if (isCancelled())
                    break;

                long id = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID));
                removed[i++] = id;
                dlm.remove(id);
                result++;
            }
            c.close();

            UpdateBuilder<Video, String> u = videoDao.updateBuilder();
            try {
                u.where().in("dlm_id", (Object[]) removed);
                u.updateColumnValue("download_status", Video.DL_STATUS_NOT_STARTED);
                u.update();
            } catch (SQLException e) {
                e.printStackTrace();
            }

            return result;
        }

        @Override
        protected void onPostExecute(Integer result) {
            if (result > 0) {
                doToast(result + " downloads cancelled.");
            } else {
                doToast("No downloads in queue.");
            }
            doOfflineVideoSetChanged();
        }

        @Override
        protected void onCancelled(Integer result) {
            if (result > 0) {
                doToast(result + " downloads cancelled.");
            }
            doOfflineVideoSetChanged();
        }
    }.executeOnExecutor(queueExecutor);
}

From source file:de.innovationgate.wgpublisher.hdb.HDBModel.java

/**
 * Do a complete reinitialisation of the database according to the model
 *//* w  w  w .  j  a va  2s  .  co  m*/
public void reinitModel() {

    if (!_core.isRunSingleNodeFunctionalities() && _core.isClusteredDatabase(_db)) {
        throw new IllegalStateException("Model reinitialisation in a cluster can only run on the master node");
    }

    Executors.newSingleThreadExecutor().execute(new Runnable() {
        @Override
        public void run() {
            _modelReinitRunning = true;
            WGA wga = WGA.get(_core);
            ProblemOccasion occ = wga.server().startProblemOccasion(HDBModel.class, _hdb.getWrappedDB(),
                    "reinitModel");
            try {
                LOG.info("Performing complete model reinitialisation.");
                _hdb.getWrappedDB().openSession();
                Iterator<Storage> children = _definition.getRootStorages().iterator();
                while (children.hasNext()) {
                    Storage child = children.next();
                    initModel(child, null, true);
                }

                List<String> oldHashes = readOldHashes();
                oldHashes.add(_definitionHash);
                writeOldHashes(oldHashes);

                LOG.info("HDBModel reinitialisation of app '" + _hdb.getWrappedDB().getDbReference()
                        + "' finished.");

            } catch (Throwable e) {
                LOG.error("Exception performing HDBModel reinitialisation", e);
                _core.getProblemRegistry()
                        .addProblem(Problem.create(occ, "exception", ProblemSeverity.HIGH, e));
            } finally {
                _modelVersionChanged = false;
                _modelReinitRunning = false;
                WGFactory.getInstance().closeSessions();
            }
        }

    });
}

From source file:br.com.bioscada.apps.biotracks.services.TrackRecordingService.java

@Override
public void onCreate() {
    super.onCreate();
    executorService = Executors.newSingleThreadExecutor();
    context = this;
    myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
    handler = new Handler();
    myTracksLocationManager = new MyTracksLocationManager(this, handler.getLooper(), true);
    activityRecognitionPendingIntent = PendingIntent.getService(context, 0,
            new Intent(context, ActivityRecognitionIntentService.class), PendingIntent.FLAG_UPDATE_CURRENT);
    activityRecognitionClient = new ActivityRecognitionClient(context, activityRecognitionCallbacks,
            activityRecognitionFailedListener);
    try {/*from   w ww. j a  v  a  2 s.c o  m*/
        activityRecognitionClient.connect();
    } catch (Exception e) {
        Log.d("BIOTRACKS", e.getMessage());
    }

    splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory());
    voiceSplitExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
    voice1Executor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
    voice2Executor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
    sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

    // onSharedPreferenceChanged might not set recordingTrackId.
    recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;

    // Require voiceExecutor and splitExecutor to be created.
    sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null);

    handler.post(registerLocationRunnable);

    /*
     * Try to restart the previous recording track in case the service has been
     * restarted by the system, which can sometimes happen.
     */
    Track track = myTracksProviderUtils.getTrack(recordingTrackId);
    if (track != null) {
        restartTrack(track);
    } else {
        if (isRecording()) {
            Log.w(TAG, "track is null, but recordingTrackId not -1L. " + recordingTrackId);
            updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true);
        }
        showNotification(false);
    }
}

From source file:com.photon.maven.plugins.android.AbstractEmulatorMojo.java

/**
 * Sends a user command to the running emulator via its telnet interface.
 *
 * @param port The emulator's telnet port.
 * @param command The command to execute on the emulator's telnet interface.
 * @return Whether sending the command succeeded.
 *//*from w  ww  . ja va 2s  .c  o  m*/
private boolean sendEmulatorCommand(
        //final Launcher launcher, 
        //final PrintStream logger,
        final int port, final String command) {
    Callable<Boolean> task = new Callable<Boolean>() {
        public Boolean call() throws IOException {
            Socket socket = null;
            BufferedReader in = null;
            PrintWriter out = null;
            try {
                socket = new Socket("127.0.0.1", port);
                out = new PrintWriter(socket.getOutputStream(), true);
                in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                if (in.readLine() == null) {
                    return false;
                }

                out.write(command);
                out.write("\r\n");
            } finally {
                try {
                    out.close();
                    in.close();
                    socket.close();
                } catch (Exception e) {
                    // Do nothing
                }
            }

            return true;
        }

        private static final long serialVersionUID = 1L;
    };

    boolean result = false;
    try {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<Boolean> future = executor.submit(task);
        result = future.get();
    } catch (Exception e) {
        getLog().error(String.format("Failed to execute emulator command '%s': %s", command, e));
    }

    return result;
}

From source file:com.loopj.android.http.AsyncHttpClientQueue.java

/**
 * Get the default threading pool to be used for this HTTP client.
 *
 * @return The default threading pool to be used
 *///from   w ww .j a v  a  2 s . c om
protected ExecutorService getDefaultThreadPool() {
    return Executors.newSingleThreadExecutor();
}

From source file:com.uwsoft.editor.data.manager.DataManager.java

public void importExternalSpineAnimationsIntoProject(final ArrayList<File> files,
        ProgressHandler progressHandler) {
    handler = progressHandler;//from   ww w  . j  a v  a 2  s .  c om
    currentPercent = 0;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            for (File file : files) {
                File copiedFile = importExternalAnimationIntoProject(file);
                if (copiedFile.getName().toLowerCase().endsWith(".atlas")) {
                    resolutionManager.resizeSpineAnimationForAllResolutions(copiedFile, currentProjectInfoVO);
                } else if (copiedFile.getName().toLowerCase().endsWith(".scml")) {
                    //resizeSpriterAnimationForAllResolutions(copiedFile, currentProjectInfoVO);
                }
            }

        }
    });
    executor.execute(new Runnable() {
        @Override
        public void run() {
            changePercentBy(100 - currentPercent);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.progressComplete();
        }
    });
    executor.shutdown();

}

From source file:de.fhg.igd.mapviewer.AbstractTileOverlayPainter.java

/**
 * Constructor/*from w ww.  ja  v a 2s .  co  m*/
 * 
 * @param numberOfThreads the number of worker threads to use for tile
 *            painting
 */
public AbstractTileOverlayPainter(int numberOfThreads) {
    try {
        loadingImage = ImageIO.read(AbstractTileOverlayPainter.class.getResource("images/loading.png"));
    } catch (IOException e) {
        throw new IllegalStateException("Could not load loading image");
    }

    if (numberOfThreads > 1) {
        executor = Executors.newFixedThreadPool(4);
    } else {
        executor = Executors.newSingleThreadExecutor();
    }
}