![](/img/trans.png)
[英]How to use AtomicInteger getAndSet correctly?
我想了解使用 Java 流和 AtomicInteger 的連續列表元素之間的區別: 輸出是: 我期待得到每個元素與以前的不同之處,如下所示: 我究竟做錯了什么? 如何得到想要的輸出? ...
[英]How to use AtomicInteger getAndSet correctly?
我想了解使用 Java 流和 AtomicInteger 的連續列表元素之間的區別: 輸出是: 我期待得到每個元素與以前的不同之處,如下所示: 我究竟做錯了什么? 如何得到想要的輸出? ...
[英]ForkJoinFramework with AtomicLong is not giving consistent result
我正在嘗試使用 ForkJoinFramework。 我知道我的代碼可能不是使用 ForkJoin 的好用例,但它至少應該可以工作...... 我正在使用 RecursiveAction 來同時修改靜態 AtomicLong 變量。 但是我在那里遇到了一些問題,結果不正確且不一致。(每次我運行它,結 ...
[英]Getting an IllegalArgumentException: Cannot convert String to AtomicInteger when trying to add data that contains an AtomicInteger int redis cache
我正在嘗試將數據 model 添加到 redis 緩存中。 當我取出 model 時,我遇到了異常 model 是 調用代碼是 我想做的是使用 redis 緩存來限制功能。 它有一個生存時間,在此期間可以多次訪問 url。 但是當調用 這會引發 IllegalArgumentException ...
[英]Is each cycle of a for loop an atomic operation?
為什么以下 AtomicBigInteger 實現的incrementAndGet方法是原子操作? 我特別想知道for (; ; )部分。 JVM 是否以某種方式保證 for 循環中的每個循環都是原子執行的? ...
[英]AtomicInteger thread safety
我怎樣才能實現這里的while循環總是執行100次。 當我執行代碼時,在極少數情況下,它會在控制台上打印 99 或 98 行,而不總是 100 行,我不明白。 ...
[英]Java auto increment from base
就我而言,我有 class 和子類。 問題是當我自動搜索我的 function 增量 id 時。 當我第一次點擊搜索時,它上傳了 5 個 id,當我添加一個並 go 返回搜索時,它上傳了 5 個我有 +(5 個舊 + 1 個新)的 id。 然后,如果我想添加新的,它會給他 id 5+6 + 1 ne ...
[英]What is the meaning of the spin in the getAndIncrement method in the AtomicInteger class?
在AtomicInteger class的getAndIncrement方法中,調用了unsafe class的getAndAddInt方法,其中包含compareAndSwapInt方法和spin(do...while)。 compareAndSwapInt 方法是線程安全的,那么為什么不只是 ...
[英]Java AtomicInteger not equal to a million after a million iterations (minimal example included)
我正在編寫一個程序,它計算數組中 0 到 100 萬(不包括)之間整數的平方。 我最多使用 8 個線程(包括)。 為了索引數組,我使用了原子 integer。 無論線程數如何,我都希望 run 方法中的 for 循環體執行一百萬次。 為了計算它執行了多少次,我使用了另一個原子 integer。 預 ...
[英]Strange output using Atomic Integer in Producer Consumer Problem in Java
在使用 BlockingQueue 實現 Java 中的生產者-消費者問題時,使用 AtomicInteger 得到奇怪的 output,其中 2 個線程產生相同的結果並將相同的計數器變量放入隊列中。 考慮到原子 Integer 使用的比較和交換技術,output 怎么可能? 它產生如下 outp ...
[英]How to observe AtomicInteger variable value change in android?
我在我的 android 應用程序中使用 AtomicInteger。 現在想聽 AtomicInteger 變量值變化,怎么聽? 如何聆聽價值變化? 如何為此 AtomicInteger 變量的值更改實現監聽器? ...
[英]Why is count1 < count2 after running the following code? Both count1 and count2 should be 2000000
在JDK11中編譯運行,看看結果。 sum1 是同步代碼所用的時間,而 sum2 是 AtomicInteger 代碼所用的時間。 count1 是對同步 count++ 的調用次數進行計數的結果。 count2 是相同數量的組合調用,但使用 AtomicInteger。 計數應為 2000 ...
[英]When AtomicInteger is faster than synchronized
我已經閱讀了大量文章,據說 AtomicInteger class 比同步構造更快。 我對 AtomicInteger 和“同步”進行了一些測試,在我的測試中,同步比 AtomicInteger 快得多。 我想知道出了什么問題:我的測試 class 不正確或 AtomicInteger 在其他情況下 ...
[英]Atomic Integers values are not getting updated in threads
我在課堂上定義了一個 atomicinterger 變量。 該類還擴展了線程類。我創建了兩個線程並在 run 方法中增加了原子整數的值。運行兩個線程后我排除了 2 的值,但我得到的值為 1。請讓我知道發生了什么下面的代碼錯了。 ...
[英]How does a thread using AtomicInteger does less number of context switching?
我正在研究 AutomaticInteger。 它指出使用 AtomicInteger 可以使整數操作非阻塞。 據說 AtomicInteger 的 compareAndSet() 方法利用了 Compare-and-set 特性。 如果比較並設置功能不成功,則返回 false。 為了使 Compa ...
[英]Atomically update 2 Long values
假設我在 Java 中有以下類: 現在我有這樣的記錄的映射ConcurrentHashMap<String, Record> recordConcurrentHashMap; 我想創建一個線程安全的正確更新函數。 目前我已經這樣做了: 我必須保持update功能同步以實現正確 ...
[英]Does AtomicInteger handle synchronization?
如果兩個線程都使用i++遞增相同的int i ,我們可能會遇到問題,因為i++不是原子操作。 這就是為什么有AtomicInteger.increment() ,它使遞增原子。 因此,如果我們有 1 個核心和 2 個線程在執行.increment() ,則絕對沒有問題(因為它不能在操作中間暫停)。 ...
[英]Volatile keyword on Atomic Variable
以下代碼在 Java 中有效 我們是否需要在AtomicInteger等原子變量上使用volatile關鍵字? 還是volatile是多余的? ...
[英]Concurrency issue when coordinating two threads
我試圖將循環的工作分成兩個線程。 我正在使用ExecutorService創建第二個線程,同時將主線程用作另一個線程。 我正在使用計數器在達到某個值時停止循環,但是我無法在這兩個線程之間同步計數器,並且循環正在運行一個額外的時間。 另外,我在主線程中使用 while 循環來了解所需的計數何時達到打印 ...
[英]Grouping based on preferences keep returning null value
public class HomeroomMix { public void calculate(String className, int number) { List<PeopleClass> people = Arrays.asList( ...
[英]Map<Object, AtomicInteger> to Associative array
我有輸入int[]具有以下內容: 使用Map<Object, AtomicInteger> ,我將其轉換為以下 object: 換句話說,我正在計算動態數組的重復元素。 現在我需要找出最大和最小出現次數,我真的被困在進一步的步驟上。 重復元素 class 的代碼如下: ...