????д????????????????Щ???
???????????? ???????[ 2015/10/12 14:03:15 ] ?????????????????? ????????
????????????????д????????????д?????????????????????????????????? Flaky ??????????????????Щ????д????????????????
??????????????????????????????????????????????? —— ??????漲?Щ???????????????????????????????Щ??С???????????????й漲???????????????Υ??????????????ν?????????????????????????? CPU ????????????????????????????????????????У???????????????????????????????????
???????????????Throttler??
???????????????????????????????????????????????????????????????????綹?棬???? CPU ?????????????????????????????????????????????“???????”????????????????????????????????????“???????”????????????????????л??????????????????????? —— ?????????????
?????????????????????????????????????????????????????????????????????
????class ThrottledException extends RuntimeException("Throttled!")
????class Throttler(count: Int) {
????private val semaphore = new Semaphore(count)
????def apply(f: => Unit): Unit = {
????if (!semaphore.tryAcquire()) throw new ThrottledException
????try {
????f
????} finally {
????semaphore.release()
????}
????}
????}
?????????????????????????????????????????????????ò????? specs2)??????????????????????????????????????????maxCount??????????????????????????????????????????????????????????“???????”?????????????????????????????????????????????????????????????2????????????
????class ThrottlerTest extends Specification {
????"Throttler" should {
????"execute sequential" in new ctx {
????var invocationCount = 0
????for (i <- 0 to maxCount) {
????throttler {
????invocationCount += 1
????}
????}
????invocationCount must be_==(maxCount + 1)
????}
????}
????trait ctx {
????val maxCount = 3
????val throttler = new Throttler(maxCount)
????}
????}
?????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????á?
???????????£?
????val e = Executors.newCachedThreadPool()
????implicit val ec: ExecutionContext=ExecutionContext.fromExecutor(e)
????private val waitForeverLatch = new CountDownLatch(1)
????override def after: Any = {
????waitForeverLatch.countDown()
????e.shutdownNow()
????}
????def waitForever(): Unit = try {
????waitForeverLatch.await()
????} catch {
????case _: InterruptedException =>
????case ex: Throwable => throw ex
????}
????ExecutionContext ???????? Future??waitForever ?????????????????????????????????????????????????????????????з???
??????

???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11