Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import sun.awt.AppContext;
  2. import javax.print.PrintServiceLookup;
  3.  
  4. public class SlowPrinting {
  5.  
  6. // Refresh interval in seconds
  7. public static int CUPS_REFRESH_INTERVAL = 30;
  8.  
  9. public static void main(String ... args) {
  10. int count = 0;
  11. long delta = 0;
  12. int delayCount = 0;
  13. while (true) {
  14. count++;
  15.  
  16. long time1 = System.currentTimeMillis();
  17.  
  18. //If either line is commented out, the program will run full speed
  19. if ((time1 - delta)/1000 > CUPS_REFRESH_INTERVAL) {
  20. delta = time1;
  21. delayCount++;
  22. System.out.println("Attempt " + delayCount + " refreshing printer listing... ");
  23. AppContext.getAppContext().put(PrintServiceLookup.class.getDeclaredClasses()[0], null);
  24. }
  25.  
  26. PrintServiceLookup.lookupPrintServices(null, null);
  27.  
  28. long time2 = System.currentTimeMillis();
  29. if (time2 - time1 > 100) {
  30. System.out.println((time2 - time1)/1000.0f + " delay detected on try #" + count+ ".");
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement