You only have to shut down a connection generated from DataSource. You can
inject a DataSource binding into a Provider<Connection> implementation and
implement get() method to return a Connection to be injected.

Thanks,

Kartik

On Sat, Jul 3, 2010 at 8:51 PM, Jason Winnebeck <[email protected]>wrote:

> I read virtually the whole Guice site, I guess I didn't connect right away
> to this page:
>
>
> http://code.google.com/docreader/#p=google-guice&s=google-guice&t=ModulesShouldBeFastAndSideEffectFree
>
> So basically it says that modules shouldn't DO any "real work" (like
> actually making connections). That leans more towards the fact that injected
> resources should be "free" to construct and then do the real init work when
> they are used (like a real pooling DataSource). I don't have a huge problem
> with this, and it makes sense.
>
> But I don't think this totally answers my question. In the example on that
> page it calls a method "addShutdownHook", which I presume is intended to
> work like java.lang.Runtime.addShutdownHook(Thread). That's nice, if you
> want the overhead of a bunch of Thread hooks and you only want to release
> resources on shutdown. Except releasing connections on shutdown is the least
> important (since the OS will do that for you). What's more important is
> cleaning up resources used temporarily in a long-running application. I'm
> thinking back to my hypothetical app which does a lot of work but has a
> "connect to DB, backup and send over FTP" which has a lot of "per-operation"
> state that should be cleaned up.
>
> Does anyone have a best-case practice to handle that using Guice? Custom
> scope? Child Injector? Right now I'm leaning towards:
>
> Create a child injector with a task-specific module
> Get the task entry point class from injector, tell it to do the task
> Tell the task-specific module to clean up (which knows about the specific
> instances it bound that need a cleanup).
>
> But this really doesn't fit with that page that says "Modules start up, but
> they don't shut down."
>
> And it also doesn't fit into the whole point of Guice that you shouldn't be
> creating your own objects (creating your own injector seems like calling new
> but trying to pretend that you aren't). Maybe if the "Task Runner" is itself
> injected...
>
> So I'm stuck at this stage of learning Guice. As an old C++ programmer I
> know "every new has a delete" and Guice is an expert at creating but gives
> you no means to destroy that I can see, so I am totally perplexed.
>
> Jason
>
>
> On 7/3/2010 4:41 PM, Jason Winnebeck wrote:
>
>> But, how do I shutdown that DataSource, or any other resource that I
>> acquire?
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to