Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

测试ID 重复 #4

Open
yuxueliang opened this issue Dec 29, 2018 · 1 comment
Open

测试ID 重复 #4

yuxueliang opened this issue Dec 29, 2018 · 1 comment

Comments

@yuxueliang
Copy link

var blockingCollection = new BlockingCollection();
List tasks = new List();
for (int i = 0; i < 100; i++)
{
var task = Task.Run(()=>{

                for (int j = 0; j < 10000; j++)
                {

                    blockingCollection.Add(new IdWorker(1,1,1).NextId());
                }
            });

            tasks.Add(task);
        }

        Task.WaitAll(tasks.ToArray());

        Console.WriteLine(blockingCollection.Distinct().Count());

        Console.ReadKey();
@jhabjan
Copy link

jhabjan commented Feb 8, 2019

There is nothing wrong with this library and it works as expected without creating duplicates. Issue here is your poor implementation. Why would you create new instance of IdWorker for every iteration? With example you provided result is as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants