Synchronizing threads across different modules

So I have two modules let's call them m1 and m2. So m1 depends on m2 and m1 starts a Thread that does some things using m2, the problem is that I need the thread in m1 and the thread in m2 to exchange information from time to time and for that I would need m2 to also depend on m1 but that creates a circular dependency and as far as I'm aware that's bad (correct me if I am wrong). How should I avoid this? Should I make another module which m1 and m2 depend on and that module handles synchronization and and everything across m1 and m2 or does that just lead to the same problem with extra steps?
31 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @nikcho-kouhai! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
0x150
0x1502y ago
are you sure this is java related you cant extend m2 from m1 and m1 from m2, that'd be circular but m2 using information from m1 and m1 using information from m2 would very well be possible
nikcho-kouhai
nikcho-kouhaiOP2y ago
it is java related and its not extending I don't think well I'm not sure if depending and extending mean the same thing they just might but yeah that's exactly what I want to avoid this circular dependency how do I get them to use information from each other without making them depend on each other?
0x150
0x1502y ago
you... dont by making m2 use information from m1, you're creating a dependency that is what a dependency is m2 requires m1 to give it information
nikcho-kouhai
nikcho-kouhaiOP2y ago
so there's no way to do it?
0x150
0x1502y ago
that's not what i said dependencies like that don't matter in java, what you cant do is extend a from b and b from a
nikcho-kouhai
nikcho-kouhaiOP2y ago
well how can I do it ?
0x150
0x1502y ago
there are a bunch of ways to do it, up to you how to solve it but it also depends on what information at what time
nikcho-kouhai
nikcho-kouhaiOP2y ago
can you perhaps elaborate a little bit? I am not exactly an expert so I don't really know the ways will doing what I said initially in the post work? In other words have a third module which both the other modules depend on and have that module handle the information exchange between the initial two modules or does that just turn into the same problem?
0x150
0x1502y ago
there's no problem here in the first place, doing it without the 3rd class would be perfectly fine but adding a 3rd would work, yes
nikcho-kouhai
nikcho-kouhaiOP2y ago
how would I do it without a third module and without making the modules dependant on each other?
0x150
0x1502y ago
you're creating a dependency if you make a get information from b as mentioned, this isn't an issue tho
nikcho-kouhai
nikcho-kouhaiOP2y ago
wtf ;-; sooo making a circular dependency isn't an issue? cause I need a to get information from b and b get information from a
0x150
0x1502y ago
making a depend on b and b depend on a is perfectly fine
nikcho-kouhai
nikcho-kouhaiOP2y ago
if it was only a getting information from b that isn't a problem, yes
0x150
0x1502y ago
you just cant make b extend a and a extend b as in, inheritance
nikcho-kouhai
nikcho-kouhaiOP2y ago
but that's for classes I'm talking about modules I do know that circular inheritance isn't a thing in java
0x150
0x1502y ago
oh jigsaw modules, sorry i thought you just referred to classes as modules god i fucking hate jigsaw btw should still be fine tho
nikcho-kouhai
nikcho-kouhaiOP2y ago
the hell is jigsaw xD?
0x150
0x1502y ago
module system it's the root cause of all the suffering in java
nikcho-kouhai
nikcho-kouhaiOP2y ago
actually contextually I can guess that it just refers to the modules depending on each other since the jigsaw goes back and forth well shit
0x150
0x1502y ago
no, jigsaw is just the name of the project the module system was introduced in fitting name
nikcho-kouhai
nikcho-kouhaiOP2y ago
ohhh well yes just the other day I was suffering because of the module system as well a bunch of shit just blew up all of a sudden my packages turned to normal folders
0x150
0x1502y ago
that's an ide problem and packages aren't part of the module system
nikcho-kouhai
nikcho-kouhaiOP2y ago
well yes but it happened as a consequence of me trying to import a project as a module in another project my module-info file just fucked itself and stopped working as a module-info file and just started working as a .java file (I could use java keywords but not keywords like module and stuff like that) I sat down on my chair and it broke (probably not a module issue but I am still blaming the modules for it because I was pretty irriated) well in any case I would still like to know is it going to be better If I make a third module to managa the informational exchange or should I just throw convention out the window, sell my soul to the devil and make a circular dependency?
0x150
0x1502y ago
whatever floats your boat both probably work, go nuts
nikcho-kouhai
nikcho-kouhaiOP2y ago
whatever floats my boat better not sink my program
0x150
0x1502y ago
nikcho-kouhai
nikcho-kouhaiOP2y ago
well alright pray for me I guess and thanks for the help
JavaBot
JavaBot2y ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@359755548973072397>.
Want results from more Discord servers?
Add your server