All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.diirt.datasource.sample.log.UnclosedPvs Maven / Gradle / Ivy

There is a newer version: 3.1.7
Show newest version
/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.datasource.sample.log;


import org.diirt.datasource.PVManager;
import static org.diirt.datasource.vtype.ExpressionLanguage.*;
import org.diirt.datasource.PVReader;
import org.diirt.datasource.PVReaderEvent;
import org.diirt.datasource.PVReaderListener;
import org.diirt.util.time.TimeDuration;
import org.diirt.vtype.VNumber;

/**
 * Shows the automatic closing of garbage collected pvs.
 * 

* Pvs must be properly closed. As a safety mechanics, pvmanager will automatically * close garbage collected pvs, and log a warning. This example shows * the mechanism in action. * * @author carcassi */ public class UnclosedPvs { public static void main(String[] args) throws Exception { System.out.println("Starting pv"); PVReader reader = PVManager.read(vNumber("sim://gaussianNoise()")) .readListener(new PVReaderListener() { @Override public void pvChanged(PVReaderEvent event) { if (event.isValueChanged()) { System.out.println("... value is " + event.getPvReader().getValue().getValue()); } } }) .maxRate(TimeDuration.ofMillis(500)); Thread.sleep(2000); System.out.println("Voiding reference"); reader = null; Thread.sleep(100); System.out.println("Garbage collecting"); System.gc(); Thread.sleep(3000); System.out.println("Closing..."); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy