Skip to content

golang question numer 13 #4

@joshvoll

Description

@joshvoll

the example of that question is on java and not on golang

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class BatchDataTransfer {
public static void main(String[] args) {
BlockingQueue channel = new ArrayBlockingQueue<>(5);

    // Producer
    new Thread(() -> {
        for (int i = 0; i < 100; i++) {
            try {
                channel.put(i);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }).start();
    
    // Consumer
    new Thread(() -> {
        while (true) {
            try {
                System.out.println(channel.take());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }).start();
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions