ConcurrentLinkedQueue چی?
ConcurrentLinkedQueue হল একটি অনবাউন্ডেড (unbounded) থ্রেড-সেফ কিউ যা লিঙ্কড নোড (linked nodes) 기반ে তৈরি। এটি FIFO (First-In-First-Out) নীতি মেনে চলে এবং একাধিক থ্রেড নিরাপদে অ্যাক্সেস করতে পারে। এটি null মান অনুমতি দেয় না।
উদাহরণ: Cơ bản ব্যবহার
ধাপ ১: প্রজেক্ট তৈরি করুন
Android Studio-তে নতুন প্রজেক্ট তৈরি করুন।
ধাপ ২: লেআউট (res/layout/activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/actionEvent"
android:textSize="40sp"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
ধাপ ৩: MainActivity.java
package com.example.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.util.concurrent.ConcurrentLinkedQueue;
public class MainActivity extends AppCompatActivity {
ConcurrentLinkedQueue<String> concurrentLinkedQueue;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
final TextView actionEvent = findViewById(R.id.actionEvent);
// FIFO ক্রমে এলিমেন্ট যোগ করুন
concurrentLinkedQueue.add("সাই");
concurrentLinkedQueue.add("রাম");
concurrentLinkedQueue.add("কৃষ্ণ");
concurrentLinkedQueue.add("প্রসাদ");
concurrentLinkedQueue.add("রাম");
actionEvent.setText("" + concurrentLinkedQueue);
}
}
ফলাফল
অ্যাপ্লিকেশন রান করলে কিউতে যোগ করা এলিমেন্টগুলো ইনসারশন ক্রমে (FIFO) দেখাবে।
