Here you can find the source of sleepMSInChunks(long ms)
Parameter | Description |
---|---|
ms | Duration to sleep for, in milliseconds. |
public static void sleepMSInChunks(long ms)
//package com.java2s; /*/* ww w . j av a 2s. co m*/ * Copyright 2012 Jeff Hain * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Sleeps in chunks of 10ms, to prevent the risk of a GC * eating the whole sleeping duration, and not letting * program enough duration to make progress. * * Useful to ensure GC-proof-ness of tests sleeping for * some time to let concurrent treatment make progress. * * @param ms Duration to sleep for, in milliseconds. */ public static void sleepMSInChunks(long ms) { final long chunkMS = 10; while (ms >= chunkMS) { try { Thread.sleep(chunkMS); } catch (InterruptedException e) { throw new RuntimeException(e); } ms -= chunkMS; } } }