Last active
August 10, 2019 16:50
-
-
Save tresf/fff28cd27055cadbf7d116951b8e2369 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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