Skip to content

Instantly share code, notes, and snippets.

@tresf
Last active August 10, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tresf/fff28cd27055cadbf7d116951b8e2369 to your computer and use it in GitHub Desktop.
Save tresf/fff28cd27055cadbf7d116951b8e2369 to your computer and use it in GitHub Desktop.
import sun.awt.AppContext;
import javax.print.PrintServiceLookup;
public class SlowPrinting {
// Refresh interval in seconds
public static int CUPS_REFRESH_INTERVAL = 30;
public static void main(String ... args) {
int count = 0;
long delta = 0;
int delayCount = 0;
while (true) {
count++;
long time1 = System.currentTimeMillis();
//If either line is commented out, the program will run full speed
if ((time1 - delta)/1000 > CUPS_REFRESH_INTERVAL) {
delta = time1;
delayCount++;
System.out.println("Attempt " + delayCount + " refreshing printer listing... ");
AppContext.getAppContext().put(PrintServiceLookup.class.getDeclaredClasses()[0], null);
}
PrintServiceLookup.lookupPrintServices(null, null);
long time2 = System.currentTimeMillis();
if (time2 - time1 > 100) {
System.out.println((time2 - time1)/1000.0f + " delay detected on try #" + count+ ".");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment