Comments (6)
Are you using any form of multi-threading when this exception occurs?
from vectorgraphics2d.
Yep, we have multithreading as following:
Create single SVGGraphics2D
object, create multiple subgraphics (SVGGraphics2D#create
) and paint in parallel.
from vectorgraphics2d.
As far as I can tell, your approach should work.
Do you also call SVGGraphics2D.getBytes()
in parallel?
VG2D was only tested with a single thread. I will try to help, but I don't know how well the current design of VG2D fits for multi-threaded use. I have do investigate a bit further on this.
from vectorgraphics2d.
Yep, this is possible in our use case.
from vectorgraphics2d.
Alright I did some investigation on this issue and found two major problems when using VG2D from multiple threads:
- The implementations of
VectorGraphics2D
, such asSVGGraphics2D
translate the method calls into an intermediate representation. This representation consists ofCommand
objects (e. g.TranslateCommand
orDrawShapeCommand
). The commands are not self-contained, which means that aDrawShapeCommand
for example behaves differently depending on the current graphics state (e.g. Color or Stroke). Therefore, when multiple threads emit commands, the result is most likely garbled. This problem can be fixed by adding state information to the commands. - The second problem is that all
SVGGraphics2D
objects created withcreate()
share a common command list. WhengetBytes()
is called in parallel, each threads processes commands from the same command list, which again causes commands likeDrawShapeCommand
to be called in the wrong graphics state. The NPE occurred, due to the same reason: One thread checked if there are commands left to process and enters an if-clause, but at the time he entered, another thread ate the remaining commands away.
Conclusion
Multi-threaded use of VG2D is currently not possible. I hate to let you down on this, @eseifert and I think that other matters are more pressing, such as changes to the overall design (see some of the other issues) to get a (more) stable API. I am afraid that you have to wait a bit longer for multi-threading to be supported with VG2D.
from vectorgraphics2d.
@seifertm Thanks a lot for the investigation and such a comprehensive answer, I understand, that switching to self-contained command system is quite a efforts and time consuming procedure. Probably separate feature request for multithreading access should be created? Anyway, well done, keep it up!
from vectorgraphics2d.
Related Issues (20)
- Improve javadoc HOT 1
- Deprecate VectorGraphics2D.getBytes() HOT 1
- Remove interface CommandHandler HOT 1
- Update wiki documentation HOT 1
- Move compression property from Processors to Documents HOT 1
- Remove close method from Document HOT 1
- Filters should operate on CommandSequence HOT 1
- Replace StreamingFilter with simpler implementation
- Improve structure of PDFDocument
- support alternative (non-base64) url for image data HOT 1
- Fix number handling for PDF output HOT 2
- Flate compression for PDF is not working
- vg2d.getCommands(); is undefined for type Graphics2D HOT 1
- bad /BBox in font 'Dialog.plain' HOT 2
- Managing GraphicsState with a Stack is unsafe HOT 3
- Bug in pdfProcessor when the PageSize starting y axis differs from zero? HOT 1
- Can multiple graphics be saved in a single PDF file? HOT 3
- Casting error
- this software is only licensed under GPL? HOT 1
- Set an automatic module name in the Jar MANIFEST HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vectorgraphics2d.