Cuando se accede concurrentemente a una colección como ArrayList, ¿cuál es la forma más sencilla de garanizar la coherencia de datos?
entre Desarrolladores
Recibe ayuda de expertos
Registrate y pregunta
Es gratis y fácil
Recibe respuestas
Respuestas, votos y comentarios
Vota y selecciona respuestas
Recibe puntos, vota y da la solución
Pregunta
Utilización de colecciones en ambientes multihilo con Java
- preguntó
- Web
- 355 Vistas
- 2 Respuestas
- solucionada
2 Respuestas
En mi opinion lo mejor es hacer que el o los metodos que accedan a la coleccion sean syncronos para que estes 100% seguro de que no habra problemas con los datos.
o si quieres saber lo que dice la documentacion puedes verlo aqui.
"Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list:"
Por favor, accede o regístrate para añadir un comentario.
Envolviendo la lista en un envoltorio sincronizado como dice Bunk3r, ejemplo:
List listaSincronizada = Collections.synchronizedList(arrayListNoSincronizado) ;
Por favor, accede o regístrate para añadir un comentario.
Por favor, accede o regístrate para responder a esta pregunta.
En el blog
-
- 406871
- 1
- Jul 5, 2015
Sin Respuesta
-
- 99
- 0
- Mar 19
-
- 65
- 1
- Feb 26
-
- 155
- 0
- Ene 30
-
- 611
- 0
- Nov 7, 2023
-
- 260
- 0
- Sep 19, 2023
-
- 286
- 0
- Ago 21, 2023
-
- 364
- 0
- May 14, 2023
-
- 324
- 0
- Abr 21, 2023
- ver todas
Actividad Reciente
Santiago2610 comentó hace 6 días
Acualizar ChoiceField en djangoSantiago2610 preguntó Mar 19
Acualizar ChoiceField en djangogonzalss preguntó Feb 26
Script /boot/ scrapingParkJo preguntó Ene 30
No me deja instalar Oracleelporfirio respondió Ene 10
Actualizar la imagen con los datos devuelto en un …ovedg preguntó Dic 31, 2023
Actualizar la imagen con los datos devuelto en un …Ehdez preguntó Nov 7, 2023
Necesito en wordpress un pluging que me calcule la…pedrourday preguntó Sep 19, 2023
Alternativas a ThreeJS y BabylonJS?pedrourday preguntó Ago 21, 2023
¿Que tecnologias y lenguajes me recomiendan?Fabio respondió Jul 11, 2023
plugin de efecto circular 3d en imagenes
Ultimas Preguntas
Usuarios Top
- Leonardo-Tadei
- 227320 Puntos
- Peter
- 150460 Puntos
- white
- 75880 Puntos
- carlossevi
- 63580 Puntos
- magarzon
- 30650 Puntos
- pregunton
- 20400 Puntos