Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:33:45+00:00 2026-06-02T17:33:45+00:00

I have the following protobuf msg defined: message Counts { repeated int32 counts =

  • 0

I have the following protobuf msg defined:

message Counts {
    repeated int32 counts = 1;
}

which is shared between threads R and W as a builder:

private final Counts.Builder countsBuilder;

Thread R will only read from countsBuilder and W will only write to countsBuilder.
The shared builder will be read, written-to and (at some point) built & sent over the network.

AFAIK, concurrent reads to messages are fine, but anything else must be synchronized at a higher level by the developer? So, I can’t actually write and read to the shared builder at the same time?

If this is not inherently thread-safe, I’m thinking of using some kind of thread-safe Collection<Integer> which I’ll use for reading/writing and will (at some point) create a brand new message right before sending it over the network. Or am I missing something?

Thanks!

EDIT 1: I’m using protobuf 2.4.1 and java 6

EDIT 2: Some terminology and spelling fixes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:33:47+00:00Added an answer on June 2, 2026 at 5:33 pm

    You should be fine if you synchronize both your read and writes:

    synchronized (countsBuilder) {
       // modify countsBuilder
    }
    

    But remember that you also need to make sure that there aren’t any race conditions when building the message; the writer thread is not allowed to make any writes after the message has been built.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a protobuf message of type OrderList message OrderList { repeated Order orders
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have following json data which I want to pass it to server using
I have following Code Block Which I tried to optimize in the Optimized section
I have the following buildr buildfile segment: require buildr/protobuf .... define protobuf-stuff do pbs
I have the following code which I'm really struggling to compile: #include <stdio.h> #include
I have following mapping definitions: <class name=Role table=Role optimistic-lock=version > <id name=Id type=Int32 unsaved-value=0
Have following error: skydos@skydos-laptop:/$ service mysql start start: Rejected send message, 1 matched rules;
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.