Search in sources :

Example 61 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project robovm by robovm.

the class ReferenceQueueTest method runLater.

private void runLater(Runnable runnable, int delayMillis) {
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    executor.schedule(runnable, delayMillis, TimeUnit.MILLISECONDS);
    executor.shutdown();
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 62 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project jgnash by ccavanaugh.

the class BudgetTableController method initialize.

@FXML
private void initialize() {
    final Preferences preferences = Preferences.userNodeForPackage(BudgetTableController.class);
    runningTotalsButton.selectedProperty().setValue(preferences.getBoolean(RUNNING_TOTALS, false));
    rateLimitExecutor = new ScheduledThreadPoolExecutor(1, new DefaultDaemonThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
    tableWidthChangeListener = (observable, oldValue, newValue) -> {
        if (newValue != null && !oldValue.equals(newValue)) {
            optimizeColumnWidths();
        }
    };
    updateHeights();
    yearSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(LocalDate.now().getYear() - YEAR_MARGIN, LocalDate.now().getYear() + YEAR_MARGIN, LocalDate.now().getYear(), 1));
    accountTreeView.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS);
    accountTreeView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
    accountTreeView.setShowRoot(false);
    accountTreeView.setEditable(true);
    accountTreeView.fixedCellSizeProperty().bind(rowHeight);
    accountSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    accountSummaryTable.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS, StyleClass.HIDE_HORIZONTAL_CSS);
    accountSummaryTable.setItems(expandedAccountList);
    accountSummaryTable.fixedCellSizeProperty().bind(rowHeight);
    accountSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountSummaryTable));
    accountTypeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    accountTypeTable.getStylesheets().add(StyleClass.HIDE_HEADER_CSS);
    accountTypeTable.setItems(accountGroupList);
    accountTypeTable.fixedCellSizeProperty().bind(rowHeight);
    accountTypeTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
    accountTypeTable.setSelectionModel(new NullTableViewSelectionModel<>(accountTypeTable));
    accountGroupPeriodSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    accountGroupPeriodSummaryTable.getStylesheets().addAll(StyleClass.HIDE_HEADER_CSS, StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
    accountGroupPeriodSummaryTable.setItems(accountGroupList);
    accountGroupPeriodSummaryTable.fixedCellSizeProperty().bind(rowHeight);
    accountGroupPeriodSummaryTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
    accountGroupPeriodSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountGroupPeriodSummaryTable));
    buildAccountTreeTable();
    buildAccountTypeTable();
    buildAccountSummaryTable();
    buildAccountGroupSummaryTable();
    accountSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountGroupPeriodSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountGroupPeriodSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountTreeView.expandedItemCountProperty().addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(this::updateExpandedAccountList));
    final ChangeListener<Object> budgetChangeListener = (observable, oldValue, newValue) -> handleBudgetChange();
    budget.addListener(budgetChangeListener);
    yearSpinner.valueProperty().addListener(budgetChangeListener);
    runningTotalsButton.selectedProperty().addListener(budgetChangeListener);
    visibleColumnCount.addListener(budgetChangeListener);
    runningTotalsButton.selectedProperty().addListener((observable, oldValue, newValue) -> preferences.putBoolean(RUNNING_TOTALS, newValue));
    /* Setting the tables as un-managed effectively removes these tables from the GridPane.  The tables are
           redundant if showing the amounts as running balances. */
    accountSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
    accountGroupPeriodSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
    horizontalScrollBar.setMin(0);
    horizontalScrollBar.maxProperty().bind(periodCount.subtract(visibleColumnCount));
    horizontalScrollBar.setUnitIncrement(1);
    horizontalScrollBar.disableProperty().bind(periodCount.lessThanOrEqualTo(1));
    // shift the table right and left with the ScrollBar value
    horizontalScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
        /* must be synchronized to prevent a race condition from multiple events and an out of
                     * bounds exception */
        synchronized (this) {
            /* don't try unless columns exist.  This can occur if the UI is not large enough to display
                         * a minimum of one period of information.
                         */
            if (periodTable.getColumns().size() > 0) {
                final int newIndex = (int) Math.round(newValue.doubleValue());
                if (newIndex > index) {
                    while (newIndex > index) {
                        handleShiftRight();
                    }
                } else if (newIndex < index) {
                    while (newIndex < index) {
                        handleShiftLeft();
                    }
                }
            }
        }
    });
    ThemeManager.fontScaleProperty().addListener((observable, oldValue, newValue) -> updateHeights());
}
Also used : Pos(javafx.geometry.Pos) Engine(jgnash.engine.Engine) BigDecimal(java.math.BigDecimal) Budget(jgnash.engine.budget.Budget) MessageProperty(jgnash.engine.message.MessageProperty) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TreeTableCell(javafx.scene.control.TreeTableCell) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) TableView(javafx.scene.control.TableView) NullTableViewSelectionModel(jgnash.uifx.control.NullTableViewSelectionModel) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) MessageListener(jgnash.engine.message.MessageListener) HBox(javafx.scene.layout.HBox) NotNull(jgnash.util.NotNull) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Spinner(javafx.scene.control.Spinner) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) BudgetGoal(jgnash.engine.budget.BudgetGoal) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) Message(jgnash.engine.message.Message) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BudgetPeriodResults(jgnash.engine.budget.BudgetPeriodResults) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TreeItem(javafx.scene.control.TreeItem) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Bindings(javafx.beans.binding.Bindings) IntegerProperty(javafx.beans.property.IntegerProperty) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) TreeTableView(javafx.scene.control.TreeTableView) ResourceBundle(java.util.ResourceBundle) ThemeManager(jgnash.uifx.skin.ThemeManager) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) Comparators(jgnash.engine.Comparators) FXMLUtils(jgnash.uifx.util.FXMLUtils) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel) CheckBox(javafx.scene.control.CheckBox) MainView(jgnash.uifx.views.main.MainView) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) TreeTableColumn(javafx.scene.control.TreeTableColumn) CommodityFormat(jgnash.text.CommodityFormat) StageUtils(jgnash.uifx.util.StageUtils) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) StyleClass(jgnash.uifx.skin.StyleClass) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) Account(jgnash.engine.Account) ChangeListener(javafx.beans.value.ChangeListener) ScrollBar(javafx.scene.control.ScrollBar) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Preferences(java.util.prefs.Preferences) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) FXML(javafx.fxml.FXML)

Example 63 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project android_frameworks_base by crdroidandroid.

the class FileOperationService method onCreate.

@Override
public void onCreate() {
    // Allow tests to pre-set these with test doubles.
    if (executor == null) {
        executor = new ScheduledThreadPoolExecutor(POOL_SIZE);
    }
    if (jobFactory == null) {
        jobFactory = Job.Factory.instance;
    }
    if (DEBUG)
        Log.d(TAG, "Created.");
    mPowerManager = getSystemService(PowerManager.class);
    mNotificationManager = getSystemService(NotificationManager.class);
}
Also used : PowerManager(android.os.PowerManager) NotificationManager(android.app.NotificationManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 64 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project webpieces by deanhiller.

the class ServerFactory method createTestServer.

static int createTestServer(boolean alwaysHttp2, Long maxConcurrentStreams) {
    BufferCreationPool pool = new BufferCreationPool();
    ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("webpieces-timer"));
    HttpFrontendManager frontEndMgr = HttpFrontendFactory.createFrontEnd("frontEnd", 10, timer, pool);
    FrontendConfig config = new FrontendConfig("id2", new InetSocketAddress(0));
    HttpServer server = frontEndMgr.createHttpServer(config, new OurListener());
    server.start();
    return server.getUnderlyingChannel().getLocalAddress().getPort();
}
Also used : FrontendConfig(org.webpieces.frontend2.api.FrontendConfig) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) HttpServer(org.webpieces.frontend2.api.HttpServer) BufferCreationPool(org.webpieces.data.api.BufferCreationPool)

Example 65 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project geode by apache.

the class QueueManagerImpl method start.

public void start(ScheduledExecutorService background) {
    try {
        blackList.start(background);
        endpointManager.addListener(endpointListener);
        // Use a separate timer for queue management tasks
        // We don't want primary recovery (and therefore user threads) to wait for
        // things like pinging connections for health checks.
        // this.background = background;
        final String name = "queueTimer-" + this.pool.getName();
        this.recoveryThread = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {

            public Thread newThread(Runnable r) {
                Thread result = new Thread(r, name);
                result.setDaemon(true);
                return result;
            }
        });
        recoveryThread.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        // TODO - use yet another Timer or the like for these tasks? We know
        // we don't want them in the recoveryThread, because the ThreadIdToSequenceIdExpiryTask
        // will wait for primary recovery.
        getState().start(background, getPool().getSubscriptionAckInterval());
        // initialize connections
        initializeConnections();
        scheduleRedundancySatisfierIfNeeded(redundancyRetryInterval);
        // When a server is removed from the blacklist, try again
        // to establish redundancy (if we need to)
        BlackListListener blackListListener = new BlackListListenerAdapter() {

            @Override
            public void serverRemoved(ServerLocation location) {
                QueueManagerImpl.this.scheduleRedundancySatisfierIfNeeded(0);
            }
        };
        blackList.addListener(blackListListener);
        factory.getBlackList().addListener(blackListListener);
    } finally {
        initializedLatch.countDown();
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BlackListListener(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListener) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BlackListListenerAdapter(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)154 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)31 Test (org.junit.Test)26 ExecutorService (java.util.concurrent.ExecutorService)24 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)22 ThreadFactory (java.util.concurrent.ThreadFactory)15 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)12 List (java.util.List)10 HashMap (java.util.HashMap)9 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)8 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)8 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 HashedWheelTimer (io.netty.util.HashedWheelTimer)8 File (java.io.File)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)7 IOException (java.io.IOException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7