admin 管理员组

文章数量: 887021


2023年12月18日发(作者:winform开发pdf)

/** *

放数据 * * @param element * @throws InterruptedException */ public void put(String element) throws InterruptedException { (); try { while (elementCount == ) { (); } elements[putIndex] = element; if (++putIndex == ) { putIndex = 0; } elementCount++; n("after put:" + (elements)); (); } finally { (); } } /** *

取数据 * * @return * @throws InterruptedException */ public String take() throws InterruptedException { (); try { while (elementCount == 0) { (); } String element = elements[takeIndex]; elements[takeIndex] = null; if (++takeIndex == ) { takeIndex = 0; } elementCount--; n("after take:" + (elements)); (); return element; } finally { (); } } public static void main(String[] args) { //启动10个读线程和10个写线程 BoundedContainer boundedContainer = new BoundedContainer(); (0, 10).forEach(i -> new Thread(() -> { try { (); } catch (InterruptedException e) { tackTrace(); } }).start()); (0, 10).forEach(i -> new Thread(() -> { try { ("hi"); } catch (InterruptedException e) { tackTrace();


本文标签: 开发 线程 作者 启动